使用多个重命名 RENAME 表达式 postgresql 时出现语法错误
Syntax error while using multiple rename RENAME expressions postgresql
我正在尝试编写一次重命名多个 table 列的查询。根据文档,语法是:
ALTER TABLE table_name
RENAME old_col_a AS new_col_a
, RENAME old_col_b AS new_col_b...;
但是,在这样做的过程中,我在第一个 RENAME 子句之后的逗号处收到语法错误:
ERROR: syntax error at or near ","
LINE 3: , RENAME
^
SQL state: 42601
Character: 1
查询适用于多个 DROP/ALTER/ADD 列和单个重命名。我终其一生都无法弄清楚为什么会发生此错误。
您需要使用多个 ALTER
语句:
ALTER TABLE table_name
RENAME COLUMN old_col_a TO new_col_a;
ALTER TABLE table_name
RENAME COLUMN old_col_b TO new_col_b;
All the forms of ALTER TABLE that act on a single table, except RENAME, SET SCHEMA, ATTACH PARTITION, and DETACH PARTITION can be combined into a list of multiple alterations to be applied together. For example, it is possible to add several columns and/or alter the type of several columns in a single command. This is particularly useful with large tables, since only one pass over the table need be made.
我正在尝试编写一次重命名多个 table 列的查询。根据文档,语法是:
ALTER TABLE table_name
RENAME old_col_a AS new_col_a
, RENAME old_col_b AS new_col_b...;
但是,在这样做的过程中,我在第一个 RENAME 子句之后的逗号处收到语法错误:
ERROR: syntax error at or near ","
LINE 3: , RENAME
^
SQL state: 42601
Character: 1
查询适用于多个 DROP/ALTER/ADD 列和单个重命名。我终其一生都无法弄清楚为什么会发生此错误。
您需要使用多个 ALTER
语句:
ALTER TABLE table_name
RENAME COLUMN old_col_a TO new_col_a;
ALTER TABLE table_name
RENAME COLUMN old_col_b TO new_col_b;
All the forms of ALTER TABLE that act on a single table, except RENAME, SET SCHEMA, ATTACH PARTITION, and DETACH PARTITION can be combined into a list of multiple alterations to be applied together. For example, it is possible to add several columns and/or alter the type of several columns in a single command. This is particularly useful with large tables, since only one pass over the table need be made.