gpt4 book ai didi

sql - 使用多个重命名 RENAME 表达式 postgresql 时出现语法错误

转载 作者:行者123 更新时间:2023-11-29 11:56:08 28 4
gpt4 key购买 nike

我正在尝试编写一次重命名多个表列的查询。根据文档,语法是:

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;

ALTER TABLE

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.

关于sql - 使用多个重命名 RENAME 表达式 postgresql 时出现语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53769166/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com