From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Антон Глушаков <a(dot)glushakov86(at)gmail(dot)com> |
Cc: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, "pgsql-admin(at)lists(dot)postgresql(dot)org" <pgsql-admin(at)lists(dot)postgresql(dot)org> |
Subject: | Re: order of pg_dump command "create sequence" |
Date: | 2025-06-06 18:48:45 |
Message-ID: | 1525849.1749235725@sss.pgh.pa.us |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
Some of your problem here comes from using an old-style SQL function.
The string body of such a function is opaque to pg_dump, so it has
no way to know about the dependency on my_seq. You could make it
new-style (SQL spec compliant) instead:
regression=# create sequence my_seq;
CREATE SEQUENCE
regression=# create function gen_id() returns character varying
regression-# begin atomic select 'PREFIX_'||nextval('public.my_seq'::regclass)::VARCHAR;
regression-# end;
CREATE FUNCTION
Now the dependency is known:
regression=# select pg_describe_object(classid,objid,objsubid) as obj, pg_describe_object(refclassid,refobjid,refobjsubid) as ref, deptype from pg_depend where objid >= 'my_seq'::regclass;
obj | ref | deptype
-------------------+-----------------+---------
function gen_id() | schema public | n
function gen_id() | sequence my_seq | n
sequence my_seq | schema public | n
(3 rows)
and pg_dump will honor it.
But as David said, using a volatile function in a GENERATED
expression is unsupported and is not going to work well.
You would probably be better off filling the column in a
BEFORE INSERT trigger.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Wasim Devale | 2025-06-11 06:21:42 | Upgrade from 12.22 to 16 |
Previous Message | Sam Stearns | 2025-06-06 15:17:37 | Re: Replication and Switchover |