Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 重命名包含空格的列_Sql_Postgresql - Fatal编程技术网

Sql 重命名包含空格的列

Sql 重命名包含空格的列,sql,postgresql,Sql,Postgresql,有人错误地创建了一个表,其中所有列名都有一个前导空格。例如:“accountid”现在是“accountid” 我将编写一个SQL语句来重命名这些列。我写的是: ALTER TABLE mytable RENAME COLUMN ' accountid' TO 'accountid'; 但是,我得到了以下错误: Error : ERROR: syntax error at or near "' accountid'" 有人能告诉我如何重命名这些吗?如何更改我的语句使其可运行?我使用Post

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

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

ALTER TABLE mytable RENAME COLUMN ' accountid' TO 'accountid';
但是,我得到了以下错误:

Error : ERROR:  syntax error at or near "' accountid'"
有人能告诉我如何重命名这些吗?如何更改我的语句使其可运行?我使用PostgreSQL


非常感谢。

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


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

select c.comment "actor.comment"  from post p join comment c on p.id = c.post_id;

如果我没有弄错的话,您在引用列名时需要双引号。非常感谢。这确实解决了上述问题。但是,它给出了另一个错误:。该列确实存在。问题是什么?非常感谢。您可以提供表的架构吗?:DCREATE TABLE mytable(“accountid”bigint not NULL),enabled“boolean NOT NULL DEFAULT false,”rowid“bigserial NOT NULL)@KZhang,weired,它在SQLFiddle上工作@KZhang:你确定你只使用了一个空格而不是几个空格或其他一些空白字符吗?
select c.comment "actor.comment"  from post p join comment c on p.id = c.post_id;