Skip to content

Getting a "Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL``" error when using Postgres ARRAY_AGG with a nullable column #11339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ruohola opened this issue Jan 23, 2022 · 2 comments · Fixed by prisma/prisma-engines#2902
Assignees
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. kind/bug A reported bug. topic: postgresql topic: raw $queryRaw(Unsafe) and $executeRaw(Unsafe): https://www.prisma.io/docs/concepts/components/prisma-cli
Milestone

Comments

@ruohola
Copy link

ruohola commented Jan 23, 2022

Bug description

I'm trying to use Postgres's ARRAY_AGG function with prisma.$queryRaw and get an error, but when I do the same query in psql (=PostgreSQL interactive terminal) I get no error.

How to reproduce

Minimal code that throws shows this issue:

schema.prisma:

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model MyTable {
  mycolumn Int?

  @@map("mytable")
}

Insert two values with psql:

INSERT INTO mytable VALUES (123), (NULL);

Works fine when querying them in psql

SELECT ARRAY_AGG(mycolumn) FROM mytable;
 array_agg
-----------
 {123,NULL}
(1 row)

Try to do the same with Prisma:

import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

await prisma.$queryRaw`SELECT ARRAY_AGG(mycolymn) from mytable;`;

We get an error:

Invalid `prisma.queryRaw()` invocation:


  Raw query failed. Code: `N/A`. Message: `error deserializing column 0: a Postgres value was `NULL``

Expected behavior

No error.

Prisma information

Schema included above.

Environment & setup

  • OS: Database in a Docker container, running Node.js/Prisma locally on macOS 12.1
  • Database: postgres:12.8-alpine3.14 (Docker image)
  • Node.js version: v14.18.3

Prisma Version

prisma                  : 3.8.1
@prisma/client          : 3.8.1
Current platform        : darwin
Query Engine (Node-API) : libquery-engine 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine        : migration-engine-cli 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine    : introspection-core 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary           : prisma-fmt 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash    : 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f
Studio                  : 0.452.0
@ruohola ruohola added the kind/bug A reported bug. label Jan 23, 2022
@ruohola ruohola changed the title Getting an Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL`` error when using Postgres ARRAY_AGG with a nullable column Getting an ``Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL```` error when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola ruohola changed the title Getting an ``Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL```` error when using Postgres ARRAY_AGG with a nullable column Getting a "Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL``" error when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola ruohola changed the title Getting a "Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL``" error when using Postgres ARRAY_AGG with a nullable column Getting a "Raw query failed. Code: \N/A\. Message: \error deserializing column 0: a Postgres value was \NULL\\" error when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola ruohola changed the title Getting a "Raw query failed. Code: \N/A\. Message: \error deserializing column 0: a Postgres value was \NULL\\" error when using Postgres ARRAY_AGG with a nullable column Getting a ````Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL" error when using Postgres ARRAY_AGG with a nullable column```` Jan 23, 2022
@ruohola ruohola changed the title Getting a ````Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL" error when using Postgres ARRAY_AGG with a nullable column```` Getting a ````Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL`````` error when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola ruohola changed the title Getting a ````Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL`````` error when using Postgres ARRAY_AGG with a nullable column Getting a ```Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL error``` when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola ruohola changed the title Getting a ```Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL error``` when using Postgres ARRAY_AGG with a nullable column Getting a ``Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL error`` when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola ruohola changed the title Getting a ``Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL error`` when using Postgres ARRAY_AGG with a nullable column Getting a "Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL error` when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola ruohola changed the title Getting a "Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL error` when using Postgres ARRAY_AGG with a nullable column Getting a "Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL``" error when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola ruohola changed the title Getting a "Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL``" error when using Postgres ARRAY_AGG with a nullable column Getting a "Raw query failed. Code: \N/A\. Message: error deserializing column 0: a Postgres value was NULL``" error when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola ruohola changed the title Getting a "Raw query failed. Code: \N/A\. Message: error deserializing column 0: a Postgres value was NULL``" error when using Postgres ARRAY_AGG with a nullable column Getting a "Raw query failed. Code: \N/A\. Message: \error deserializing column 0: a Postgres value was \NULL\\" error when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola ruohola changed the title Getting a "Raw query failed. Code: \N/A\. Message: \error deserializing column 0: a Postgres value was \NULL\\" error when using Postgres ARRAY_AGG with a nullable column Getting a ``Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL```` error when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola ruohola changed the title Getting a ``Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL```` error when using Postgres ARRAY_AGG with a nullable column Getting a ```Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL````` error when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola ruohola changed the title Getting a ```Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL````` error when using Postgres ARRAY_AGG with a nullable column Getting a ````Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL`````` error when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola ruohola changed the title Getting a ````Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL`````` error when using Postgres ARRAY_AGG with a nullable column Getting a `````Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL``````` error when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola ruohola changed the title Getting a `````Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL``````` error when using Postgres ARRAY_AGG with a nullable column Getting a ``Raw query failed. Code: \N/A\. Message: \error deserializing column 0: a Postgres value was NULL``````` error when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola ruohola changed the title Getting a ``Raw query failed. Code: \N/A\. Message: \error deserializing column 0: a Postgres value was NULL``````` error when using Postgres ARRAY_AGG with a nullable column Getting a ```Raw query failed. Code: N/A. Message: \error deserializing column 0: a Postgres value was NULL ``` error when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola ruohola changed the title Getting a ```Raw query failed. Code: N/A. Message: \error deserializing column 0: a Postgres value was NULL ``` error when using Postgres ARRAY_AGG with a nullable column Getting a ```Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL ``` error when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola ruohola changed the title Getting a ```Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL ``` error when using Postgres ARRAY_AGG with a nullable column Getting a "Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL``" error when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola ruohola changed the title Getting a "Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL``" error when using Postgres ARRAY_AGG with a nullable column Getting a "Raw query failed. Code: N/A. Message: ```error deserializing column 0: a Postgres value was NULL`````" error when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola ruohola changed the title Getting a "Raw query failed. Code: N/A. Message: ```error deserializing column 0: a Postgres value was NULL`````" error when using Postgres ARRAY_AGG with a nullable column Getting a "Raw query failed. Code: N/A. Message: ```error deserializing column 0: a Postgres value was NULL `" error when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola ruohola changed the title Getting a "Raw query failed. Code: N/A. Message: ```error deserializing column 0: a Postgres value was NULL `" error when using Postgres ARRAY_AGG with a nullable column Getting a "Raw query failed. Code: N/A. Message: ``error deserializing column 0: a Postgres value was NULL `" error when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola ruohola changed the title Getting a "Raw query failed. Code: N/A. Message: ``error deserializing column 0: a Postgres value was NULL `" error when using Postgres ARRAY_AGG with a nullable column Getting a "Raw query failed. Code: N/A. Message: ```error deserializing column 0: a Postgres value was NULL ``" error when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola ruohola changed the title Getting a "Raw query failed. Code: N/A. Message: ```error deserializing column 0: a Postgres value was NULL ``" error when using Postgres ARRAY_AGG with a nullable column Getting a "Raw query failed. Code: N/A. Message: ````error deserializing column 0: a Postgres value was NULL ```" error when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola ruohola changed the title Getting a "Raw query failed. Code: N/A. Message: ````error deserializing column 0: a Postgres value was NULL ```" error when using Postgres ARRAY_AGG with a nullable column Getting a "Raw query failed. Code: N/A. Message: ``error deserializing column 0: a Postgres value was NULL````" error when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola ruohola changed the title Getting a "Raw query failed. Code: N/A. Message: ``error deserializing column 0: a Postgres value was NULL````" error when using Postgres ARRAY_AGG with a nullable column Getting a "Raw query failed. Code: N/A. Message: ``error deserializing column 0: a Postgres value was \NULL````" error when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola ruohola changed the title Getting a "Raw query failed. Code: N/A. Message: ``error deserializing column 0: a Postgres value was \NULL````" error when using Postgres ARRAY_AGG with a nullable column Getting a "Raw query failed. Code: N/A. Message: ` error deserializing column 0: a Postgres value was NULL `" error when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola ruohola changed the title Getting a "Raw query failed. Code: N/A. Message: ` error deserializing column 0: a Postgres value was NULL `" error when using Postgres ARRAY_AGG with a nullable column Getting a "Raw query failed. Code: N/A. Message: `` error deserializing column 0: a Postgres value was NULL ``" error when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola ruohola changed the title Getting a "Raw query failed. Code: N/A. Message: `` error deserializing column 0: a Postgres value was NULL ``" error when using Postgres ARRAY_AGG with a nullable column Getting a "Raw query failed. Code: N/A. Message: error deserializing column 0: a Postgres value was NULL``" error when using Postgres ARRAY_AGG with a nullable column Jan 23, 2022
@ruohola
Copy link
Author

ruohola commented Jan 23, 2022

I concede, it's impossible to escape backticks in PR titles :D

ruohola added a commit to apilytics/apilytics that referenced this issue Jan 24, 2022

Verified

This commit was signed with the committer’s verified signature.
ruohola Eero Ruohola
The issue was that `prisma.$queryRaw` doesn't seem to support Postgres's
`ARRAY_AGG` with null column values.

More info: prisma/prisma#11339
ruohola added a commit to apilytics/apilytics that referenced this issue Jan 24, 2022

Verified

This commit was signed with the committer’s verified signature.
ruohola Eero Ruohola
The issue was that `prisma.$queryRaw` doesn't seem to support Postgres's
`ARRAY_AGG` with null column values.

More info: prisma/prisma#11339

Also, just render these `0` status codes as `'unknown'` in the frontend.
We could just filter these away completely in the SQL, but if someone is
using a bugged self-made integration and doesn't send valid status codes
(we have to keep the status-code in the middleware API as nullable) it
could make their dashboard show no data.
ruohola added a commit to apilytics/apilytics that referenced this issue Jan 24, 2022

Verified

This commit was signed with the committer’s verified signature.
ruohola Eero Ruohola
The issue was that `prisma.$queryRaw` doesn't seem to support Postgres's
`ARRAY_AGG` with null column values.

More info: prisma/prisma#11339

Also, just render these `0` status codes as `'unknown'` in the frontend.
We could just filter these away completely in the SQL, but if someone is
using a bugged self-made integration and doesn't send valid status codes
(we have to keep the status-code in the middleware API as nullable) it
could make their dashboard show no data.
ruohola added a commit to apilytics/apilytics that referenced this issue Jan 24, 2022

Verified

This commit was signed with the committer’s verified signature.
ruohola Eero Ruohola
The issue was that `prisma.$queryRaw` doesn't seem to support Postgres's
`ARRAY_AGG` with null column values.

More info: prisma/prisma#11339

Also, just render these `0` status codes as `'unknown'` in the frontend.
We could just filter these away completely in the SQL, but if someone is
using a bugged self-made integration and doesn't send valid status codes
(we have to keep the status-code in the middleware API as nullable) it
could make their dashboard show no data.
ruohola added a commit to apilytics/apilytics that referenced this issue Jan 24, 2022

Verified

This commit was signed with the committer’s verified signature.
ruohola Eero Ruohola
The issue was that `prisma.$queryRaw` doesn't seem to support Postgres's
`ARRAY_AGG` with null column values.

More info: prisma/prisma#11339

Also, just render these `0` status codes as `'unknown'` in the frontend.
We could just filter these away completely in the SQL, but if someone is
using a bugged self-made integration and doesn't send valid status codes
(we have to keep the status-code in the middleware API as nullable) it
could make their dashboard show no data.
@matthewmueller matthewmueller added domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. topic: postgresql topic: raw $queryRaw(Unsafe) and $executeRaw(Unsafe): https://www.prisma.io/docs/concepts/components/prisma-cli bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Jan 28, 2022
@matthewmueller
Copy link
Contributor

matthewmueller commented Jan 28, 2022

We appreciate the effort! We have a handful of other raw issues. I see us tackling this all in one go soonish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. kind/bug A reported bug. topic: postgresql topic: raw $queryRaw(Unsafe) and $executeRaw(Unsafe): https://www.prisma.io/docs/concepts/components/prisma-cli
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants