| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | jonas-lugner(at)gmx(dot)de |
| Cc: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Subject: | Re: BUG #19757: attname in pg_attribute not strictly updated when renaming a column |
| Date: | 2026-10-14 15:02:09 |
| Message-ID: | 1174131.1791990129@sss.pgh.pa.us |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
PG Bug reporting form <noreply(at)postgresql(dot)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
| From | Date | Subject | |
|---|---|---|---|
| Previous Message | Sebastian Webber | 2026-10-14 14:45:14 | Re: BUG #19756: ALTER COLUMN TYPE USING gives wrong values on partitions with IS NULL |