sqldatabasepostgresqlsyntax-erroralter

syntax error at or near "-" in PostgreSQL


I'm 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?


Solution

  • I have reproduced 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

    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