Re: order of pg_dump command "create sequence"

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: order of pg_dump command "create sequence"
Дата
Msg-id 1525849.1749235725@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: order of pg_dump command "create sequence"  (Антон Глушаков <a.glushakov86@gmail.com>)
Список 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



В списке pgsql-admin по дате отправления: