NeilTheSeal
NeilTheSeal

Reputation: 21

PostgreSQL - How do I cancel what I am typing in psql terminal if I make a typo?

I am just getting started with SQL, and while I work I am making a lot of typos. For instance, after running psql mydatabase, I tried to make a table -

postgres=# CREATE TABLE table_name (
postgres=(# _id serial PRIMARY KEY
postgres=(# name VARCHAR (50) UNIQUE NOT NULL,
postgres=(# 

and at that point, I realize that I forgot a comma after PRIMARY KEY. How do I just cancel everything that I am typing and start the command from scratch? I couldn't find any answers via Google or StackOverflow, despite this surely being a common problem.. Do I just type ABORT; or is that something completely different? Working from Windows PowerShell, if that makes any difference.

EDIT: I checked the commands and apparently you can type \r and press enter to reset the query buffer. Keeping this posted for other newbies

Upvotes: 2

Views: 1409

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 247270

The normal way to get out is to send a SIGINT signal to psql, typically by pressing Ctrl+C (unless you configured your terminal differently).

Unless you are stuck in a string (prompt ends in ='# or ='>), you can also use \r to reset the query buffer.

If desperate, you can also quit psql with \q and restart it.

Upvotes: 4

Related Questions