public inbox for [email protected]  
help / color / mirror / Atom feed
From: Tom Lane <[email protected]>
To: Isaac Morland <[email protected]>
Cc: Ashutosh Bapat <[email protected]>
Cc: Jason Song <[email protected]>
Cc: [email protected]
Subject: Re: Does RENAME TABLE rename associated identity sequence?
Date: Thu, 24 Apr 2025 13:40:05 -0400
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAMsGm5e4gT3HNaRZDRbdzC3gg=kp6YKQVq48prMwEUAfh9zOFg@mail.gmail.com>
References: <CAK9ZnjPRH04S5foDBh82ymP+jgQbYFiQ8E9TMQisSr8bhnUbDg@mail.gmail.com>
	<CAExHW5uJF2nK+NCMvwOFR9yE+5b30z6DM5pFS68FZTowMozPNw@mail.gmail.com>
	<CAMsGm5e4gT3HNaRZDRbdzC3gg=kp6YKQVq48prMwEUAfh9zOFg@mail.gmail.com>

Isaac Morland <[email protected]> writes:
> On Thu, 24 Apr 2025 at 05:53, Ashutosh Bapat <[email protected]>
> 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






view thread (2+ messages)

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected]
  Subject: Re: Does RENAME TABLE rename associated identity sequence?
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox