Support "ALTER FOREIGN TABLE ... RENAME CONSTRAINT ..."

From: Ian Lawrence Barwick <barwick(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Support "ALTER FOREIGN TABLE ... RENAME CONSTRAINT ..."
Date: 2026-10-30 07:20:38
Message-ID: CAB8KJ=gBwpo+iXR5n_NQ1xude3Ms2P3n=OmL6F=B=VSNgCXgfw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi

Currently it's possible to do:

ALTER TABLE foo RENAME COLUMN bar TO baz;
ALTER FOREIGN TABLE ft_foo RENAME COLUMN bar TO baz;

and:

ALTER TABLE foo RENAME CONSTRAINT alice TO bob;

but for some reason not:

ALTER FOREIGN TABLE ft_foo RENAME CONSTRAINT alice TO bob;

even though ALTER FOREIGN TABLE ... ADD / DROP CONSTRAINT is possible.

I appreciate this is very niche, but I ran into it when working intensively
with foreign tables and was annoyed enough to start writing a patch.

I can't see any reason not to do this, the code change is fairly small, and
ALTER FOREIGN TABLE has other non-standard extensions anyway.

I should note that "ALTER TABLE ... RENAME CONSTRAINT" does work on all
table-like objects [*]; this wasn't obvious to me when I first ran into the
issue, and it seems inconsistent that "OWNER TO" works with both "ALTER TABLE"
and "ALTER FOREIGN TABLE".

[*] https://www.postgresql.org/docs/current/sql-altertable.html#SQL-ALTERTABLE-DESC-RENAME

The attached patch implements this; note I had to do a bit of refactoring in
tcop/utility.c to ensure the correct command tag is returned. Patch includes
test, documentation and psql tab completion (the latter also adds support for
related ALTER FOREIGN TABLE grammar items, as it would be harder not to add
them; it is not meant as an attempt to add all missing ALTER FOREIGN TABLE
items).

Regards

Ian Barwick

Attachment Content-Type Size
v1-0001-Support-ALTER-FOREIGN-TABLE-.-RENAME-CONSTRAINT.patch application/octet-stream 11.3 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Bertrand Drouvot 2026-10-30 07:26:58 Re: Fix cumulative WAL statistics double-counting from parallel workers
Previous Message Masahiko Sawada 2026-10-30 07:14:38 Re: [PG19] pg_upgrade --check passes, then the upgrade fails