-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Prepared statement caching is data dependent on numeric input parameters (incorrect binary data format in bind parameter x) #22482
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.tech/enginesIssue for tech Engines.Issue for tech Engines.topic: postgresqltopic: 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
When I run a raw query with a numeric parameter, the sequence of values for that parameter can cause error 22PO3 - incorrect binary data format.
Related issue: #16611
How to reproduce
Test code:
await prisma.$queryRaw(
Prisma.sql`select * from version() where LENGTH("version") > ${1}`,
);
await prisma.$queryRaw(
Prisma.sql`select * from version() where LENGTH("version") > ${1.1}`,
);Success cases:
- Run query with decimal value (1.1) first, then query with integer value.
Failure cases:
- Run query with integer value (1) first, then query with decimal value. Throws code 22PO3 - incorrect binary data format.
Workarounds:
- Disabling Prisma's prepared statement cache (
?statement_cache_size=0) prevents the issue from occurring. - Manually serializing the input value to a string and then casting to a Postgres decimal type separately prevents the issue from occurring (
${n.toFixed(2)}::decimal)
Expected behavior
Prisma prepared statement caching should not prevent varying numeric types from being passed in as parameters.
Prisma information
See test code above.
Environment & setup
- OS: macOS
- Database: PostgreSQL
- Node.js version: v18.18.2
Prisma Version
5.7.1
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.tech/enginesIssue for tech Engines.Issue for tech Engines.topic: postgresqltopic: 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