Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xH0Up-00000002lt7-2wXZ for pgsql-bugs@arkaria.postgresql.org; Wed, 14 Oct 2026 15:02:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xH0Un-00000003rOS-2R8k for pgsql-bugs@arkaria.postgresql.org; Wed, 14 Oct 2026 15:02:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xH0Un-00000003rOK-1MWN for pgsql-bugs@lists.postgresql.org; Wed, 14 Oct 2026 15:02:21 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xH0Uk-000000025BH-30fR for pgsql-bugs@lists.postgresql.org; Wed, 14 Oct 2026 15:02:21 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 69EF29Aq1174132; Wed, 14 Oct 2026 11:02:10 -0400 From: Tom Lane 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 In-reply-to: <19757-c2dcdf7e64e5f1c7@postgresql.org> References: <19757-c2dcdf7e64e5f1c7@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Wed, 14 Oct 2026 14:04:55 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1174130.1791990129.1@sss.pgh.pa.us> Date: Wed, 14 Oct 2026 11:02:09 -0400 Message-ID: <1174131.1791990129@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form 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