Skip to content

Prepared statement caching is data dependent on numeric input parameters (incorrect binary data format in bind parameter x) #22482

@lbebels

Description

@lbebels

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions