https://www.prisma.io/ logo
#orm-help
Title
# orm-help
h

Han Han

09/23/2022, 1:06 AM
Hi, I have a problem with
dbgenerated
Postgresql look like that:
Copy code
CREATE OR REPLACE FUNCTION create_payment_id_code(INTEGER) RETURNS text AS $$
SELECT CASE
    WHEN $1 < 10000 THEN 'PM' || to_char($1, 'FM00000')
    ELSE concat('TT', $1)
  END;
$$ LANGUAGE sql immutable;

ALTER TABLE public.payments
ADD COLUMN "paymentIdCode" TEXT UNIQUE NOT NULL GENERATED ALWAYS AS (create_payment_id_code("paymentId")) STORED;
When I use
prisma db pull
Copy code
paymentIdCode              String?                    @unique @default(dbgenerated("create_payment_id_code(\"paymentId\")"))
when run migrate then get the error:
ERROR: cannot use column reference in DEFAULT expression.
1
n

Nurul

09/23/2022, 3:52 PM
Hi Han 👋 In dbgenerated you would need to pass a PostgreSQL function. For reference here’s a comment for a similar GitHub Issue.
v

Vladi Stevanovic

09/26/2022, 1:49 PM
👋 Hello @Han Han - did you have a chance to check the comment Nurul mentioned? Let us know if this question is answered!
6 Views