Postgresql:语法错误在" - "附近

Ope*_*ous 16 postgresql

我正在尝试运行查询以使用更新用户密码.

alter user dell-sys with password 'Pass@133';
Run Code Online (Sandbox Code Playgroud)

但是因为-它给了我错误,

ERROR:  syntax error at or near "-"
LINE 1: alter user dell-sys with password 'Pass@133';
                       ^
Run Code Online (Sandbox Code Playgroud)

任何人都可以照亮它吗?

Atu*_*ind 25

我在我的系统中重新生成了这个问题,

postgres=# alter user my-sys with password 'pass11';
ERROR:  syntax error at or near "-"
LINE 1: alter user my-sys with password 'pass11';
                       ^
Run Code Online (Sandbox Code Playgroud)

这是问题,

psql要求输入,你再次给出了alter query,看看postgres-#这就是为什么它在alter上给出了错误

postgres-# alter user "my-sys" with password 'pass11';
ERROR:  syntax error at or near "alter"
LINE 2: alter user "my-sys" with password 'pass11';
        ^
Run Code Online (Sandbox Code Playgroud)

解决方案就像错误一样简单,

postgres=# alter user "my-sys" with password 'pass11';
ALTER ROLE
Run Code Online (Sandbox Code Playgroud)


Clo*_*eto 14

用双引号括起来

alter user "dell-sys" with password 'Pass@133';
Run Code Online (Sandbox Code Playgroud)

请注意,您必须使用在使用双引号创建用户时使用的相同案例.假设您创建了"Dell-Sys"那么每当您引用该用户时,您必须完全相同.

我认为你做的最好的事情就是删除那个用户并重新创建没有非法标识符字符而没有双引号,这样你以后可以在任何情况下引用它.