Reputation: 21
lecture3-# SELECT * FROM flights;
ERROR: syntax error at or near "psql"
LINE 1: psql
This was the code and error. I have added the path link on Environment Variables> System variables> Path edited and added two links underneath
C:\Program Files\PostgreSQL\12\bin
C:\Program Files\PostgreSQL\12\lib
So, if my links are proper why it is showing this
ERROR: syntax error at or near "psql"
Upvotes: 2
Views: 13175
Reputation: 11
The solution from – user330315 worked for me. Silly mistake to run psql from the pgadmin psql command prompt. I ran the same query with semicolon from the windows command prompt, it worked! The directory i used was programFiles/posgresql/bin folder.
Upvotes: 1
Reputation: 13
When writing in psql the answer is the semicolon!
You can close out your former syntax error(s) and move on by simply using ";"
For example: Here I have accidently pressed "k" and hit enter and then wrote my intended code:
mydb=# k
mydb=# SELECT * FROM person
mydb-# WHERE country_of_birth = 'Poland';
When I tried to run the code it hit me with the following error.
ERROR: syntax error at or near "k"
LINE 1: k
^
The solution:
mydb=# ;
By entering the semicolon, it retroactively closed out the accidental k query with no result and now I am able to re-run my intended code and get an error free result.
Upvotes: 0
Reputation: 91
This happened because you had an unfinished statement from earlier. So, or you finish it or abort it.
Your psql prompt indicates this.
Statement without ";":
<DATABASE>=# <SOME UNFINISHED STATEMENT...>
And then a simple query in catalog:
<DATABASE>-# SELECT * FROM pg_settings;
ERROR: syntax error at or near "some"
LINE 1: <SOME UNFINISHED STATEMENT...>
^
Notice that your prompt changed from "=#" to "-#". The "-#" indicates that there is a statement that isn't finished.
Let's try again:
<DATABASE>=# <SOME UNFINISHED STATEMENT...>
Abort with <Ctrl>+<C>
<DATABASE>-# ^C
Your prompt is ready again :)
<DATABASE>=#
Upvotes: 9