I have connected to my PSQL database on command line and can run commands like \dt
or similar just fine.
However, when I type in a basic query such as SELECT * FROM myTable
and hit return, it does not display anything and just goes to the next line waiting for another command.
Any idea why?
You need to terminate the query with ;
SELECT * FROM myTable;
There is actually a less obvious cause of the above. If you've ommitted a closing bracket ()
) somewhere in the query, you'll get the same behaviour. E.g.
SELECT *
FROM some_table
WHERE (NOW() - date_value;
It won't attempt to execute the statement until it gets a closing );
before it spits out a syntax error. While the above is fairly obvious where the issue it, it gets a lot trickier to spot with more complex queries. To get out of it, close with multiple brackets )))))))));
which will still resolve and spit out the syntax error so you can continue and correct.
A way to spot if this is the case, is to use the Up arrow through your history - if you're not seeing your previously typed (but not yet executed) statements, then you know you're still in a state where it's trying to close the statement before attempting a syntax check.
The issue isn't limited to brackets, but any other closing symbol such as quotes. The trick is to pay attention to the psql
prompt as it shows the parsing state. E.g.;
DATABASE=>
the =>
means all is normal and it's parsing a single lineDATABASE->
the ->
means you're on a new line and likely missing a ;
DATABASE(>
the (>
means you haven't closed a bracketDATABASE'>
the '>
means you haven't closed a quote.Etc, you get the idea.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With