question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Query Postgres Table with UUID as ID raises error

See original GitHub issue

If I try to query a row from a postgres table with a id of type UUID prisma raises an error.

Postgres version: PostgreSQL 11.1 (Debian 11.1-1.pgdg90+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit

Prisma2 version: 2.0.0-alpha.159

DB Script:

CREATE TABLE public."User"
(
    age integer,
    name text COLLATE pg_catalog."default" NOT NULL DEFAULT ''::text,
    id uuid NOT NULL DEFAULT uuid_generate_v1(),
    CONSTRAINT id PRIMARY KEY (id)
)
WITH (
    OIDS = FALSE
)
TABLESPACE pg_default;

ALTER TABLE public."User"
    OWNER to postgres;

Schema:

model User {
id   String @default(uuid()) @id
age  Int?
name String
post Post[]
}

Code:

const MyFunc = async function() {
  const MyUser = await photon.users.findOne({where: {id: "936958ea-cb04-11e9-bcba-0242ac110002"},});
  console.log(MyUser);
}

MyFunc()

Error: Reason: Error in connector: Error querying the database: error serializing parameter 0: cannot convert to or from a Postgres value of type uuid

Queries on same table with findMany() is working perfect.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
benjamincanaccommented, Oct 3, 2019

Any update on this? I encounter the same problem.

Thanks!

0reactions
pantharshit00commented, Jan 3, 2021

image

Confirmed as well 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Postgres UUID type error - Stack Overflow
You might need to add explicit type casts. I tried with adding the schema like: id uuid PRIMARY KEY DEFAULT public.uuid_generate_v4() (as seen ......
Read more >
Auto-generated primary keys: UUID, serial or identity column?
This article explores the old question what to use for autogenerated primary keys: UUID, serial or identity column?
Read more >
What happens when an automatically generated UUID ...
Upon each insert where an UUID is not specified, a new UUID (v4) is automatically generated to be set as the primary key....
Read more >
A Complete Guide to UUIDs in PostgreSQL - Arctype
The foundation for a table in a relational database is the primary key. Because of its importance, we have to give special consideration...
Read more >
GraphQL and UUID type on Postgres - Hasura
Enumeration of entries: Another problem is that it's very easy to enumerate all the entries of your table with a primary key. A...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found