0

When I try to run a command in the psql shell, it doesn't work and I have to enter it again. For example, if I run SELECT * FROM flights;, it won't run and says

ERROR:  syntax error at or near "SELECT"
LINE 2: SELECT * FROM flights;
        ^

But, when I try it again, it works completely fine. Help! I'm using the windows version.

(It only works some times)

CrazyVideoGamer
  • 754
  • 8
  • 22

1 Answers1

1

psql doesn't run the query when you hit "enter", it runs the query when it sees a semicolon. You're getting this error because you forgot the semicolon in the previous query.

For example:

test=> select 1
test-> select 1;
ERROR:  syntax error at or near "select"
LINE 2: select 1;
        ^

The query sent to the server is select 1 select 1, hence the syntax error on LINE 2.

The hint that you're in the middle of an unterminated command is the terminal prompt, which changes from test=> to test-> after the first line.

Nick Barnes
  • 19,816
  • 3
  • 51
  • 63