1

I sometimes get syntax error at or near the commands, but the next try it works fine.

DROP DATABASE:

Superman-# DROP DATABASE a;
ERROR:  syntax error at or near "DROP"
LINE 2: DROP DATABASE a;
        ^
Superman=# DROP DATABASE a;
DROP DATABASE

and also the CREAT DATABASE:

Superman=# CREATE DATABSE task1database;
ERROR:  syntax error at or near "DATABSE"
LINE 1: CREATE DATABSE task1database;
           ^
Superman=# CREATE DATABASE a;
CREATE DATABASE
Superman=# CREATE DATABASE task1database;
CREATE DATABASE
2
  • DATABSE in your second example in the error message should tell you something. Does DATABSE look right? Commented Nov 27, 2019 at 1:28
  • 2
    Maybe you didn't finish the previous line correctly, like forgetting a semicolon? Commented Nov 27, 2019 at 1:54

1 Answer 1

9

Observe the prompt in the first line:

Superman-#

The - is a sign that this is a continuation line, that is, you didn't finish whatever you wrote on the previous line with a semicolon.

The resulting SQL statement that is sent to the server is everything since the last semicolon, so the DROP DATABASE is somewhere in the middle of the string and causes a syntax error.

Always observe the prompt, and if it does not contain a =, you can clear the buffer by pressing Ctrl+C.

The second example is just a typo in DATABSE.

Sign up to request clarification or add additional context in comments.

1 Comment

I find the default prompts too subtle in psql. I use \set PROMPT2 '...> ' to make the "continuation line" be way more obvious.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.