Postgresql:“-”处或附近的语法错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18656545/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Postgresql : syntax error at or near "-"
提问by OpenCurious
I am Trying to run a query to update the user password using.
我正在尝试运行查询以使用更新用户密码。
alter user dell-sys with password 'Pass@133';
But because of -
it's giving me error like,
但因为-
它给了我这样的错误,
ERROR: syntax error at or near "-"
LINE 1: alter user dell-sys with password 'Pass@133';
^
Can Anyone shade a light on it?
任何人都可以在上面遮光吗?
回答by Atul Arvind
I have Regenerated the issue in my system,
我在我的系统中重新生成了这个问题,
postgres=# alter user my-sys with password 'pass11';
ERROR: syntax error at or near "-"
LINE 1: alter user my-sys with password 'pass11';
^
Here is the issue,
问题来了,
psql is asking for input and you have given again the alter query see postgres-#
That's why it's giving error at alter
psql 正在要求输入,您再次给出了更改查询,请参阅postgres-#
这就是为什么它在更改时出错的原因
postgres-# alter user "my-sys" with password 'pass11';
ERROR: syntax error at or near "alter"
LINE 2: alter user "my-sys" with password 'pass11';
^
Solution is as simple as the error,
解决方案就像错误一样简单,
postgres=# alter user "my-sys" with password 'pass11';
ALTER ROLE
回答by Clodoaldo Neto
Wrap it in double quotes
用双引号括起来
alter user "dell-sys" with password 'Pass@133';
Notice that you will have to use the same case you used when you created the user using double quotes. Say you created "Dell-Sys"
then you will have to issue exact the same whenever you refer to that user.
请注意,您必须使用与使用双引号创建用户时使用的相同大小写。假设您创建了,"Dell-Sys"
那么每当您引用该用户时,您都必须发出完全相同的内容。
I think the best you do is to drop that user and recreate without illegal identifier characters and without double quotes so you can later refer to it in any case you want.
我认为您最好的做法是删除该用户并在没有非法标识符字符和双引号的情况下重新创建,以便您以后可以在任何情况下引用它。
回答by Walters
i was trying trying to GRANT read-only privileges to a particular table to a user called walters-ro. So when i ran the sql command # GRANT SELECT ON table_name TO walters-ro; --- i got the following error..`syntax error at or near “-”
我试图将特定表的只读权限授予名为 walters-ro 的用户。所以当我运行 sql 命令时 # GRANT SELECT ON table_name TO walters-ro; --- 我收到以下错误.. “-”处或附近的“语法错误”
The solution to this was basically putting the user_name into double quotes since there is a dash(-) between the name.
对此的解决方案基本上是将 user_name 放入双引号中,因为名称之间有一个破折号(-)。
GRANT SELECT ON table_name TO "walters-ro";
GRANT SELECT ON table_name TO "walters-ro";
That solved the problem.
那解决了问题。