Postgresql: syntax error in or near "-"

I am trying to run a query to update a user password using.

alter user dell-sys with password 'Pass@133'; 

But because of - it gives me an error, for example,

 ERROR: syntax error at or near "-" LINE 1: alter user dell-sys with password 'Pass@133'; ^ 

Can someone obscure the light on him?

+8
postgresql
source share
2 answers

I fixed the problem on 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 problem

psql asks for input, and you again asked for a change, see postgres-# . Therefore, it gives an error when changing

 postgres-# alter user "my-sys" with password 'pass11'; ERROR: syntax error at or near "alter" LINE 2: alter user "my-sys" with password 'pass11'; ^ 

The solution is as simple as a mistake,

 postgres=# alter user "my-sys" with password 'pass11'; ALTER ROLE 
+19
source share

Wrap it in double quotes

 alter user "dell-sys" with password 'Pass@133'; 

Note that you will have to use the same case that you used when creating the user using double quotes. Suppose you created "Dell-Sys" , then you have to issue the same thing when you refer to this user.

I think the best thing is to abandon this user and recreate it without illegal identifier characters and without double quotes so that you can later refer to it anyway.

+7
source share

All Articles