serial not accepted as datatype in ALTER TABLE ... ALTER COLUMN

Поиск
Список
Период
Сортировка
От Ashutosh Bapat
Тема serial not accepted as datatype in ALTER TABLE ... ALTER COLUMN
Дата
Msg-id CAExHW5vwCauLutJwcmbvHKttp8-eL5_EMichmKw32HGESpwFjA@mail.gmail.com
обсуждение исходный текст
Ответы Re: serial not accepted as datatype in ALTER TABLE ... ALTER COLUMN  (Andy Fan <zhihuifan1213@163.com>)
Список pgsql-hackers
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



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Jelte Fennema-Nio
Дата:
Сообщение: Re: Support a wildcard in backtrace_functions
Следующее
От: Dave Cramer
Дата:
Сообщение: Re: [PATCH] Add native windows on arm64 support