-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Float number on raw query: incorrect binary data format in bind parameter 1 #17110
Copy link
Copy link
Closed
Labels
bug/2-confirmedBug has been reproduced and confirmed.Bug has been reproduced and confirmed.kind/bugA reported bug.A reported bug.topic: floating point typesTopic related to floating point types and precision lossTopic related to floating point types and precision losstopic: prepared statement cachetopic: raw$queryRaw(Unsafe) and $executeRaw(Unsafe): https://www.prisma.io/docs/concepts/components/prisma-cli$queryRaw(Unsafe) and $executeRaw(Unsafe): https://www.prisma.io/docs/concepts/components/prisma-cli
Milestone
Description
Bug description
error when trying to send a float number to raw query:
db error: ERROR: invalid byte sequence for encoding "UTF8"
How to reproduce
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
const generate = async (): Promise<void> => {
const result2 = await prisma.$queryRawUnsafe(`SELECT $1`, 100)
console.log(result2) // [ { '?column?': '100' } ] works!
const result = await prisma.$queryRawUnsafe(`SELECT $1`, 9.9)
console.log(result) // Error
// prisma 4.8.0 db error: ERROR: incorrect binary data format in bind parameter 1
// prisma 3.15.2 Raw query failed. Code: `22021`. Message: `db error: ERROR: invalid byte sequence for encoding "UTF8": 0x00`
}
generate()
.catch((error) => {
console.error(error)
process.exit(1)
})
.finally(async () => {
await prisma.$disconnect()
})Expected behavior
[ { '?column?': '9.9' } ]
Prisma information
anyEnvironment & setup
- OS: MAC
- Database: PostgreSQL
- Node.js version: ˆ16
Prisma Version
tested on prisma 4.8.0 and prisma 3.15.2
Solution
when we add a ; to the first query it works fine
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
const generate = async (): Promise<void> => {
const result2 = await prisma.$queryRawUnsafe(`SELECT $1;`, 100)
console.log(result2) // [ { '?column?': '100' } ] works!
const result = await prisma.$queryRawUnsafe(`SELECT $1`, 9.9)
console.log(result) // [ { '?column?': 9.9 } ] works!
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bug/2-confirmedBug has been reproduced and confirmed.Bug has been reproduced and confirmed.kind/bugA reported bug.A reported bug.topic: floating point typesTopic related to floating point types and precision lossTopic related to floating point types and precision losstopic: prepared statement cachetopic: raw$queryRaw(Unsafe) and $executeRaw(Unsafe): https://www.prisma.io/docs/concepts/components/prisma-cli$queryRaw(Unsafe) and $executeRaw(Unsafe): https://www.prisma.io/docs/concepts/components/prisma-cli