Support "ALTER FOREIGN TABLE ... RENAME CONSTRAINT ..."
Support "ALTER FOREIGN TABLE ... RENAME CONSTRAINT ..."
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
Re: Support "ALTER FOREIGN TABLE ... RENAME CONSTRAINT ..."
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
I didn’t realize this before, so I looked into it a bit more. It seems that ALTER FOREIGN TABLE on a plain table is rejected except for RENAME COLUMN. The others simply fail with a “... is not a foreign table” error. On the other hand, ALTER TABLE on a foreign table is always accepted as long as the operation makes sense for foreign tables.
The patch also allows running ALTER FOREIGN TABLE ... RENAME CONSTRAINT on a plain table. I’m not sure whether we should keep allowing it, given that RENAME COLUMN works for plain tables too while the others are simply rejected.
There are also more strange things with RENAME; for example, commands like ALTER FOREIGN TABLE <materialized view> RENAME COLUMN or ALTER INDEX <foreign table> RENAME also work.