Re: Switching identity column to serial

From: Ron <ronljohnsonjr(at)gmail(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Switching identity column to serial
Date: 2023-02-04 04:42:05
Message-ID: 3410451d-667f-b198-0d06-17a998c144b5@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2/3/23 22:41, Ron wrote:
> On 2/3/23 18:54, Erik Wienhold wrote:
>> I was wondering if it's possible to drop a column identity (not the column
>> itself) while keeping the attached sequence. This would avoid recreating
>> an identical sequence (especially with a correct start value and owner).
>
> Why doesn't this work?
> BEGIN;
> DROP SEQUENCE t_id;
> CREATE SEQUENCE new_t_id_seq AS INTEGER OWNED BY t.id;
> ALTER SEQUENCE new_t_id_seq OWNER TO new_owner;
> SELECT setval('new_t_id', (SELECT MAX(id) FROM t));
> SELECT nextval('new_t_id');
> COMMIT;

Note: this was not tested...

--
Born in Arizona, moved to Babylonia.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Erik Wienhold 2023-02-04 20:55:52 Re: Switching identity column to serial
Previous Message Ron 2023-02-04 04:41:06 Re: Switching identity column to serial