Skip to content

.raw errors on date params w/ Postgres #2533

@cap10morgan

Description

@cap10morgan

Bug description

When running a raw SQL query with prisma.raw and template literal params, I get the error below when querying on timestamp columns:

error: PrismaClientKnownRequestError: Raw query failed. Code: `22P03`. Message: `db error: ERROR: incorrect binary data format in bind parameter 2`
  engine       at NodeEngine.graphQLToJSError (/Users/wmorgan/dev/safe-office/api/node_modules/@prisma/engine-core/dist/NodeEngine.js:590:1)
  engine       at /Users/wmorgan/dev/safe-office/api/node_modules/@prisma/engine-core/dist/NodeEngine.js:498:1
  engine       at process.result (internal/process/task_queues.js:97:5)
  engine       at PrismaClientFetcher.request (/Users/wmorgan/dev/safe-office/api/node_modules/@prisma/client/src/runtime/getPrismaClient.ts:628:13) {
  engine     code: 'P2010',
  engine     meta: {
  engine       code: '22P03',
  engine       message: 'db error: ERROR: incorrect binary data format in bind parameter 2'
  engine     }
  engine   }
  engine }

How to reproduce

  1. Create a DB table in Postgres with a timestamp without time zone field.
  2. Query it via prisma.raw like this: prisma.raw`select * from table where tzfield=${dateValue}`
    1. For dateValue I tested with both ISO-formatted date strings and JS Date objects.

Expected behavior

The query works and returns the same data as a query not involving timestamp fields.

Environment & setup

  • OS: macOS
  • Database: PostgreSQL
  • Prisma version: 2.0.0-beta.5
  • Node.js version: v12.16.3

Metadata

Metadata

Labels

bug/2-confirmedBug has been reproduced and confirmed.kind/bugA reported bug.tech/enginesIssue for tech Engines.tech/typescriptIssue for tech TypeScript.topic: raw$queryRaw(Unsafe) and $executeRaw(Unsafe): https://www.prisma.io/docs/concepts/components/prisma-cli

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions