41

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?

1

4 Answers 4

58

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
0
26

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.

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.

2
  • Tried this one, it's giving ERROR: syntax error at or near "alter" LINE 2: alter user "dell-sys" with password 'Pass@133'; Sep 6, 2013 at 11:24
  • 1
    @Heliconia are you sure your previous line is ended with semicolon? Sep 6, 2013 at 11:36
1

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 “-”

The solution to this was basically putting the user_name into double quotes since there is a dash(-) between the name.

# GRANT SELECT ON table_name TO "walters-ro";

That solved the problem.

0

I got the similar error below:

ERROR: syntax error at or near ")"
LINE 4: );

Because I put a trailing comma mistakenly as shown below:

CREATE TABLE person(
  id SERIAL PRIMARY KEY,
  name VARCHAR(20),
               -- ↑ A trailing comma
);

So, I removed the a trailing comma as shown below:

CREATE TABLE person(
  id SERIAL PRIMARY KEY,
  name VARCHAR(20)
               -- ↑ No trailing comma
);

Then, the error was solved:

CREATE TABLE

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.