pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: jonas-lugner@gmx.de
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #19757: attname in pg_attribute not strictly updated when renaming a column
Date: Wed, 14 Oct 2026 11:02:09 -0400
Message-ID: <1174131.1791990129@sss.pgh.pa.us> (raw)
In-Reply-To: <19757-c2dcdf7e64e5f1c7@postgresql.org>
References: <19757-c2dcdf7e64e5f1c7@postgresql.org>

PG Bug reporting form <noreply@postgresql.org> writes:
> Consider the following Code:

> CREATE TABLE employees (
>                            email VARCHAR(255) UNIQUE
> );

> ALTER TABLE employees RENAME COLUMN email TO contact_email;

> This generates two entries, but for one of those the attname remains `email`
> and is not updated to `contact_email` accordingly.

This is not a bug.

The second pg_attribute row you are seeing is for the index
underlying the unique constraint.  Index column names are an
arbitrary implementation detail, and we don't try to make them
track table column names.  For that matter, we don't rename
the index itself either.  So, looking at the behavior of your
example with psql:

regression=# CREATE TABLE employees (
                           email VARCHAR(255) UNIQUE
);
CREATE TABLE
regression=# \d employees
                     Table "public.employees"
 Column |          Type          | Collation | Nullable | Default 
--------+------------------------+-----------+----------+---------
 email  | character varying(255) |           |          | 
Indexes:
    "employees_email_key" UNIQUE CONSTRAINT, btree (email)

regression=# \d employees_email_key
         Index "public.employees_email_key"
 Column |          Type          | Key? | Definition 
--------+------------------------+------+------------
 email  | character varying(255) | yes  | email
unique, btree, for table "public.employees"

regression=# ALTER TABLE employees RENAME COLUMN email TO contact_email;
ALTER TABLE
regression=# \d employees
                        Table "public.employees"
    Column     |          Type          | Collation | Nullable | Default 
---------------+------------------------+-----------+----------+---------
 contact_email | character varying(255) |           |          | 
Indexes:
    "employees_email_key" UNIQUE CONSTRAINT, btree (contact_email)

regression=# \d employees_email_key
           Index "public.employees_email_key"
 Column |          Type          | Key? |  Definition   
--------+------------------------+------+---------------
 email  | character varying(255) | yes  | contact_email
unique, btree, for table "public.employees"

			regards, tom lane






view thread (2+ messages)

Message-ID: <1174131.1791990129@sss.pgh.pa.us>
Permalink:  ../1174131.1791990129@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1174131.1791990129@sss.pgh.pa.us

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, jonas-lugner@gmx.de
  Subject: Re: BUG #19757: attname in pg_attribute not strictly updated when renaming a column
  In-Reply-To: <1174131.1791990129@sss.pgh.pa.us>
  References: <19757-c2dcdf7e64e5f1c7@postgresql.org> <1174131.1791990129@sss.pgh.pa.us>

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

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