This happens with the following client config:
val dbClient = Postgres
.Client()
.withCredentials(user = postgresUser, password = postgresPassword)
.database(postgresDb)
.withSessionPool
.maxSize(1)
.withBinaryParams(true)
.withBinaryResults(true)
.newRichClient(postgresHost)
(If .withBinaryParams/.withBinaryResults is set to false the inserts work)
Reproduction
Database setup:
create table foo (n numeric(6,2));
Scala:
def insertBigDecimal(bd: BigDecimal) =
sql"""insert into foo (n) values ($bd)"""
.exec(dbClient)
.map(rc => s"inserted $rc rows")
.handle{ case _ => "failed to insert" }
val a = BigDecimal(10)
val b = BigDecimal(10.0)
val c = BigDecimal("1E+1")
val d = BigDecimal("10")
val fa = insertBigDecimal(a)
val fb = insertBigDecimal(b)
val fc = insertBigDecimal(c)
val fd = insertBigDecimal(d)
println(a, Await.result(fa)) // (10,inserted 1 rows)
println(b, Await.result(fb)) // (10.0,inserted 1 rows)
println(c, Await.result(fc)) // (1E+1,failed to insert)
println(d, Await.result(fd)) // (10,inserted 1 rows)