Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

psql prompt changes from dbname=# to dbname-# or dbname(#

If I type something wrong into psql, default dbname=# changes to either dbname-# or dbname(# and normal commands no longer work. How do I get it back to dbname=#?

like image 277
Matt Avatar asked Oct 30 '25 14:10

Matt


1 Answers

You tried to run a statement with unbalanced parentheses.

So psql thinks you're going to write more of the same statement and is waiting for input.

psql will not treat a semicolon as end-of-statement when there's an open quoted string, there are unbalanced parantheses, etc, since sometimes semicolons appear within statements in such cases. So ;` won't work.

craig=> CREATE TABLE (
craig(> 
craig(> ;
craig(> 

Use \r or \reset to clear the in-progress query buffer.

Control-C has the same effect, but it'll also cancel an in-progress statement sent to the server, and on Windows it'll exit psql completely. So you should prefer to use \r:

craig=> CREATE TABLE (
craig(> 
craig(> ;
craig(> 
craig(> \r
Query buffer reset (cleared).
craig=> 
like image 144
Craig Ringer Avatar answered Nov 01 '25 14:11

Craig Ringer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!