Hi All, alter table t1 add column c serial; ALTER TABLE this works, but not #alter table t1 add column c int; ALTER TABLE #alter table t1 alter column c type serial; ERROR: type "serial" does not exist
Looking at the documentation [1], the grammar for both mentions data_type ADD [ COLUMN ] [ IF NOT EXISTS ] column_name data_type and ALTER [ COLUMN ] column_name [ SET DATA ] TYPE data_type data_type is described on that page as "Data type of the new column, or new data type for an existing column." but CREATE TABLE documentation [2] redirects data_type to [3], which mentions serial. The impression created by the documentation is the second statement above is a valid statement as should not throw an error; instead change the data type of the column (and create required sequence). In code ATPrepAlterColumnType() calls typenameTypeIdAndMod(), whereas transformColumnDefinition() (called for ALTER TABLE ... ADD COLUMN and CREATE TABLE) handles "serial" data type separately. Looks like we are missing a call to transformColumnDefinition() in transformAlterTableStmt() under case AT_AlterColumnType. [1] https://www.postgresql.org/docs/current/sql-altertable.html [2] https://www.postgresql.org/docs/16/sql-createtable.html [3] https://www.postgresql.org/docs/16/datatype.html -- Best Wishes, Ashutosh Bapat