Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uNc7Y-005aYM-Dn for pgsql-admin@arkaria.postgresql.org; Fri, 06 Jun 2025 18:48:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uNc7W-00FbBY-F2 for pgsql-admin@arkaria.postgresql.org; Fri, 06 Jun 2025 18:48:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uNc7W-00FbBQ-3o for pgsql-admin@lists.postgresql.org; Fri, 06 Jun 2025 18:48:50 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uNc7U-000afm-2k for pgsql-admin@lists.postgresql.org; Fri, 06 Jun 2025 18:48:50 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 556Imj0n1525850; Fri, 6 Jun 2025 14:48:45 -0400 From: Tom Lane To: =?UTF-8?B?0JDQvdGC0L7QvSDQk9C70YPRiNCw0LrQvtCy?= cc: "David G. Johnston" , "pgsql-admin@lists.postgresql.org" Subject: Re: order of pg_dump command "create sequence" In-reply-to: References: Comments: In-reply-to =?UTF-8?B?0JDQvdGC0L7QvSDQk9C70YPRiNCw0LrQvtCy?= message dated "Fri, 06 Jun 2025 18:09:04 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1525848.1749235725.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 06 Jun 2025 14:48:45 -0400 Message-ID: <1525849.1749235725@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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=3D# create sequence my_seq; CREATE SEQUENCE regression=3D# create function gen_id() returns character varying regression-# begin atomic select 'PREFIX_'||nextval('public.my_seq'::regcl= ass)::VARCHAR; regression-# end; CREATE FUNCTION Now the dependency is known: regression=3D# select pg_describe_object(classid,objid,objsubid) as obj, p= g_describe_object(refclassid,refobjid,refobjsubid) as ref, deptype from pg= _depend where objid >=3D '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