2

有人错误地创建了一个表,其中所有列名都有一个前导空格。例如:“accountid”现在是“accountid”。

我将编写一条 SQL 语句来重命名这些列。我写的是:

ALTER TABLE mytable RENAME COLUMN ' accountid' TO 'accountid';

但是,我收到以下错误:

Error : ERROR:  syntax error at or near "' accountid'"

有人可以指导我如何重命名这些吗?如何更改我的语句以使其可运行?我使用 PostgreSQL。

非常感谢。

4

2 回答 2

7

在 PostgreSQL 中,您使用双引号作为标识符(如果需要):"

ALTER TABLE mytable RENAME COLUMN " accountid" TO "accountid";

请参阅此处并浏览至 4.1.1

于 2012-10-19T14:46:39.497 回答
0

您甚至可以放置其他字符:

select c.comment "actor.comment"  from post p join comment c on p.id = c.post_id;
于 2014-07-10T19:51:30.657 回答