Skip to content

[BUG]: BigInt is losing precision in postgres due to drizzle using JSON conversion in query #4894

@kedrzu

Description

@kedrzu

Report hasn't been filed before.

  • I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

0.44.5

What version of drizzle-kit are you using?

0.31.4

Other packages

No response

Describe the Bug

Here is SQL executed by drizzle:

SELECT "consultationOutput"."id",
       "consultationOutput"."consultation_id",
       "consultationOutput"."language",
       "consultationOutput"."status",
       "consultationOutput"."diagnosis",
       "consultationOutput"."treatment",
       "consultationOutput"."prescriptions",
       "consultationOutput"."updated_at",
       "consultationOutput_consultation"."data" AS "consultation"
FROM "consultation_output" "consultationOutput"
LEFT JOIN LATERAL
  (SELECT json_build_array("consultationOutput_consultation"."patient_id") AS "data"
   FROM
     (SELECT *
      FROM "consultation" "consultationOutput_consultation"
      WHERE "consultationOutput_consultation"."id" = "consultationOutput"."consultation_id"
      LIMIT $1) "consultationOutput_consultation") "consultationOutput_consultation" ON TRUE
WHERE "consultationOutput"."id" = $2
LIMIT $3 

There is some whacky JSON array, which contains bigint ids.
They are converted to number and lose precision.
There is no way of parsing them to bigint using custom drizzle type or postgres.js transforms, because JSON transformation (thus precision losing) happens in db.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions