Re: Two sequences associated with one identity column

2025-10-30 Thread Adrian Klaver
On 10/30/25 08:22, Rumpi Gravenstein wrote: I've seen two indexes created on the same table/column when you create a primary key as part of table create ddl and then also run a separate create index statement for the same table/column. Yes it is possible to create two indexes on a given table

Re: Two sequences associated with one identity column

2025-10-30 Thread Rumpi Gravenstein
I've seen two indexes created on the same table/column when you create a primary key as part of table create ddl and then also run a separate create index statement for the same table/column. On Thu, Oct 30, 2025 at 10:42 AM Adrian Klaver wrote: > On 10/30/25 01:55, Colin 't Hart wrote: > >

Re: Two sequences associated with one identity column

2025-10-30 Thread Adrian Klaver
On 10/30/25 01:55, Colin 't Hart wrote: relname | relnamespace | relpersistence --+--+o |524799410 | p |524799410 | p (2 rows) Well so much for that guess. I was exploring the idea that the sequence may hav

Re: Two sequences associated with one identity column

2025-10-30 Thread Colin 't Hart
relname | relnamespace | relpersistence --+--+ |524799410 | p |524799410 | p (2 rows) On Wed, 29 Oct 2025 at 17:28, Adrian Klaver wrote: > > On 10/29/25 06:40, Colin 't Hart wrote: > > As expected the dump contain

Re: Two sequences associated with one identity column

2025-10-29 Thread Adrian Klaver
On 10/29/25 06:40, Colin 't Hart wrote: As expected the dump contains: CREATE TABLE . ( , id bigint NOT NULL ); -- -- Name: ; Type: SEQUENCE; Schema: ; Owner: -- ALTER TABLE . ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY ( SEQUENCE NAME . START WITH 1 INCREMENT BY 1

Re: Two sequences associated with one identity column

2025-10-29 Thread Peter Eisentraut
On 29.10.25 12:27, Colin 't Hart wrote: One of my clients has a database in which a single identity column (called "id" in that table) has two sequences associated with it(!) Both sequences display Sequence for identity column: ..id when described with \d in psql. Inserting fails with "ERROR

Re: Two sequences associated with one identity column

2025-10-29 Thread Ron Johnson
I'd have expected the CREATE SEQUENCE and ALTER TABLE to be separate that can go in the post-data section, and be there even in schema-only dumps because it was easier for whoever added sections to pg_dump. After all, what really matters is the destination, not the journey. On Wed, Oct 29, 2025 a

Re: Two sequences associated with one identity column

2025-10-29 Thread Adrian Klaver
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 s

Re: Two sequences associated with one identity column

2025-10-29 Thread kurt thepw . com
are "create table as select.."-ing from the old table you might get the two sequences again. I've never used "create table as select" . An alternative might be to pg_dump just that table, edit the .sql file, drop the table, and then restore. Kurt __

Re: Two sequences associated with one identity column

2025-10-29 Thread Colin 't Hart
As expected the dump contains: CREATE TABLE . ( , id bigint NOT NULL ); -- -- Name: ; Type: SEQUENCE; Schema: ; Owner: -- ALTER TABLE . ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY ( SEQUENCE NAME . START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1 );

Re: Two sequences associated with one identity column

2025-10-29 Thread David G. Johnston
On Wednesday, October 29, 2025, Dominique Devienne wrote: > On Wed, Oct 29, 2025 at 2:17 PM kurt thepw.com wrote: > >If this is a development database, perhaps you can do a schema-only > pg_dump of it in plain text format, manually edit out the offending second > sequence from the resulting

Re: Two sequences associated with one identity column

2025-10-29 Thread Dominique Devienne
On Wed, Oct 29, 2025 at 2:17 PM kurt thepw.com wrote: >If this is a development database, perhaps you can do a schema-only > pg_dump of it in plain text format, manually edit out the offending second > sequence from the resulting SQL file, and restore it into a new database. I'm surprised

Re: Two sequences associated with one identity column

2025-10-29 Thread kurt thepw . com
x27;t Hart Sent: Wednesday, October 29, 2025 8:20 AM To: PostgreSQL General Subject: Re: Two sequences associated with one identity column Again as I wrote above, drop identity complains about more than one sequence. I have no idea how this customer arrived at this situation or if it affects

Re: Two sequences associated with one identity column

2025-10-29 Thread Colin 't Hart
Again as I wrote above, drop identity complains about more than one sequence. I have no idea how this customer arrived at this situation or if it affects other environments (this is actually a dev database that we're trying to upgrade as the first step in an upgrade project). I suspect the dump w

Re: Two sequences associated with one identity column

2025-10-29 Thread hubert depesz lubaczewski
On Wed, Oct 29, 2025 at 01:04:48PM +0100, Colin 't Hart wrote: > Thanks. But as I wrote above, trying to alter either of the two > sequences and specifying "owned by none" results in the error. Sorry, missed that. Can you please provide pg_dump output from this db, just schema, just this one tabl

Re: Two sequences associated with one identity column

2025-10-29 Thread Colin 't Hart
Thanks. But as I wrote above, trying to alter either of the two sequences and specifying "owned by none" results in the error. /Colin On Wed, 29 Oct 2025 at 13:02, hubert depesz lubaczewski wrote: > > On Wed, Oct 29, 2025 at 12:27:44PM +0100, Colin 't Hart wrote: > > One of my clients has a data

Re: Two sequences associated with one identity column

2025-10-29 Thread hubert depesz lubaczewski
On Wed, Oct 29, 2025 at 12:27:44PM +0100, Colin 't Hart wrote: > One of my clients has a database in which a single identity column > (called "id" in that table) has two sequences associated with it(!) > Both sequences display > Sequence for identity column: ..id > when described with \d in psql. >

Two sequences associated with one identity column

2025-10-29 Thread Colin 't Hart
Hi, One of my clients has a database in which a single identity column (called "id" in that table) has two sequences associated with it(!) Both sequences display Sequence for identity column: ..id when described with \d in psql. Inserting fails with "ERROR: more than one owned sequence found