Re: Does RENAME TABLE rename associated identity sequence?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Isaac Morland <isaac(dot)morland(at)gmail(dot)com>
Cc: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>, Jason Song <pidaoh(at)g(dot)skku(dot)edu>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Does RENAME TABLE rename associated identity sequence?
Date: 2025-04-24 17:40:05
Message-ID: 1654819.1745516405@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Isaac Morland <isaac(dot)morland(at)gmail(dot)com> writes:
> On Thu, 24 Apr 2025 at 05:53, Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
> wrote:
>> If there's any problem, IMO, ALTER TABLE ... RENAME ... should rename the
>> sequence too since the identity sequences are created implicitly when the
>> table is created, so they should be renamed implicitly. We should not
>> require WITH SEQUENCE clause.

> My concern would be what happens if the new sequence name is not available.
> I suppose the simplest behaviour might be to skip renaming the sequence in
> that case, perhaps raising a warning.

We do not rename any other subsidiary objects such as indexes.
Why would we rename a sequence (which has a lot more reason
to be considered an independent object than an index does)?

regression=# create table foo (i int primary key);
CREATE TABLE
regression=# \d+ foo
Table "public.foo"
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
--------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
i | integer | | not null | | plain | | |
Indexes:
"foo_pkey" PRIMARY KEY, btree (i)
Not-null constraints:
"foo_i_not_null" NOT NULL "i"
Access method: heap

regression=# alter table foo rename to bar;
ALTER TABLE
regression=# \d+ bar
Table "public.bar"
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
--------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
i | integer | | not null | | plain | | |
Indexes:
"foo_pkey" PRIMARY KEY, btree (i)
Not-null constraints:
"foo_i_not_null" NOT NULL "i"
Access method: heap

I think it's up to the user to rename subsidiary objects if
they wish to do so.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2025-04-24 17:44:05 Re: POC: enable logical decoding when wal_level = 'replica' without a server restart
Previous Message Isaac Morland 2025-04-24 17:30:41 Re: Does RENAME TABLE rename associated identity sequence?