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 1vE7eM-005knv-7s for pgsql-general@arkaria.postgresql.org; Wed, 29 Oct 2025 14:59:45 +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 1vE7eK-001ce5-RL for pgsql-general@arkaria.postgresql.org; Wed, 29 Oct 2025 14:59:43 +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 1vE7eK-001cdx-Gm for pgsql-general@lists.postgresql.org; Wed, 29 Oct 2025 14:59:43 +0000 Received: from fhigh-a7-smtp.messagingengine.com ([103.168.172.158]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vE7eH-004tth-1i for pgsql-general@lists.postgresql.org; Wed, 29 Oct 2025 14:59:43 +0000 Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfhigh.phl.internal (Postfix) with ESMTP id 133E014001D7; Wed, 29 Oct 2025 10:59:39 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Wed, 29 Oct 2025 10:59:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1761749979; x=1761836379; bh=7KxDUau/j8/kDx/Vy6gYqL54zuEG0k18qtWo1BjykhE=; b= MLMPSK2BpDJpo1vrMC+bzASwVNFJnL/zd2EBlXubZ+Q3Pzu51SSTSwL1jx5JnciO o4zi9dZ73q88t1zbfFEKwQ7sSNQKV686g04v/IqCTgS5t6mXCtmYTGoq09uLOK/e 1tl8mJM6q9lKnDu2yurNLzNMLGw8KOYKbgOW8e7sjcrzG/gNlGU6b3h8os3e3M2E i19aBKvMYKK4KiB7m95XmlX3PlUh3+GcEwgWYFJrDHu9WAgTwQZtnNOuadH2PzEo MeAPhPfJE4SGRjhMdjs8hC9k1er9LkTLFQbamMJad++UyQ1Hnnd8HLv7MzHH0TWV NUrdA3CaMPY2dU1P8WBcCQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1761749979; x=1761836379; bh=7 KxDUau/j8/kDx/Vy6gYqL54zuEG0k18qtWo1BjykhE=; b=T4pXxGGwAfHuRVPpB 3KMmVD6mrUW4jFG/7q+kMI047xm1G5KhcCDnTN4wQZh8YmX8UTGi31VDdozbmDsU hQqYBQdATfjLl91QVwYEsXYQex74tph6aqy9BspcNWE2sL7AYPF52TQdtCIuv6IM RRtxADgtuI3xzEpEfcmUwq3KNwnXozXgQBvldyO4h7L6fJlPrRzoP6A3jV6RnHKv HCRpWdeuXErIUbLbKiWlj/yHS36GiWQd4B0/cXK+nwDUksgx3IsrYy2950JdeidA cWhXIxWqSP2on+AIe7vMUAEmY+i1qQDyOLb1c4/GfCnKYbHUgDXjYFNXJVCnY1XM 4VVRQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggdduieegtdefucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepkfffgggfuffvfhfhjggtgfesthekredttddvjeenucfhrhhomheptegurhhirghn ucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmqe enucggtffrrghtthgvrhhnpedvveeuheeuvefhudeftefhueehvefftdelkeeujeetgfdt gfeitddvjeefleffleenucffohhmrghinhepshgvqhgpthgvshhtrdhiugenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhl rghvvghrsegrkhhlrghvvghrrdgtohhmpdhnsggprhgtphhtthhopeefpdhmohguvgepsh hmthhpohhuthdprhgtphhtthhopehkuhhrthesthhhvghpfidrtghomhdprhgtphhtthho pegtohhlihhnthhhrghrthesghhmrghilhdrtghomhdprhgtphhtthhopehpghhsqhhlqd hgvghnvghrrghlsehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 29 Oct 2025 10:59:38 -0400 (EDT) Message-ID: <93c76800-58f6-432f-825e-863e2410e3f5@aklaver.com> Date: Wed, 29 Oct 2025 07:59:37 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Two sequences associated with one identity column To: "kurt thepw.com" , Colin 't Hart , PostgreSQL General References: Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 10/29/25 07:47, kurt thepw.com wrote: > > < > < CREATE TABLE . ( > < , > <   id bigint NOT NULL > < ); > < > > I've never seen a plaintext pg_dump  output where the sequence > associated with a column in a table was not mentioned in s "DEFAULT > nextval(..." modifier in that column's line of the CREATE TABLE > statement, ex: > > < > < CREATE TABLE . ( > <    id integer DEFAULT nextval('.'::regclass) NOT NULL, > <    ..., > <   .  .  .  .  . > <  ); That is for case where someone manually creates DEFAULT: create table manual_seq_test(id integer default nextval('test_seq'), fld_1 varchar, fld_2 boolean); pg_dump -d test -U postgres -p 5432 -t manual_seq_test CREATE TABLE public.manual_seq_test ( id integer DEFAULT nextval('public.test_seq'::regclass), fld_1 character varying, fld_2 boolean ); Otherwise for system generated sequences you get: create table seq_test(id serial, fld_1 varchar, fld_2 boolean); CREATE TABLE public.seq_test ( id integer NOT NULL, fld_1 character varying, fld_2 boolean ); CREATE SEQUENCE public.seq_test_id_seq AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1; ALTER SEQUENCE public.seq_test_id_seq OWNER TO postgres; -- -- Name: seq_test_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres -- ALTER SEQUENCE public.seq_test_id_seq OWNED BY public.seq_test.id; -- -- Name: seq_test id; Type: DEFAULT; Schema: public; Owner: postgres -- ALTER TABLE ONLY public.seq_test ALTER COLUMN id SET DEFAULT nextval('public.seq_test_id_seq'::regclass); OR create table id_test(id integer generated always as identity, fld_1 varchar, fld_2 boolean); CREATE TABLE public.id_test ( id integer NOT NULL, fld_1 character varying, fld_2 boolean ); ALTER TABLE public.id_test OWNER TO postgres; -- -- Name: id_test_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres -- ALTER TABLE public.id_test ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY ( SEQUENCE NAME public.id_test_id_seq START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1 ); > > With the sequence already created earlier in the dump file. But then, > I've never before seen a table column with two associated sequences. > Maybe that is what makes pg_dump generate the > > "ALTER TABLE . ALTER COLUMN id ADD GENERATED..." > > Statements. -- Adrian Klaver adrian.klaver@aklaver.com