Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there an option that can change the "exit external editor -> query runs automatically" behaviour of the psql \e switch ? (Other than intentionally mangling the query syntax).

share|improve this question
up vote 5 down vote accepted

Don't add a semicolon (;) and you are fine. I quote the manual about the \e or \edit meta-command here:

... if the query ends with (or contains) a semicolon, it is immediately executed. Otherwise it will merely wait in the query buffer; type semicolon or \g to send it, or \r to cancel.

share|improve this answer

If you have many request and some semicolons use Transaction :

In psql open editor mode \e:

-- at start of edited text 
-- ...  your requests here
-- save exit

Back to psql : your requests are executed but change are not written :

If all is OK, save changes with :


else If you have errors or want to cancel :

share|improve this answer

You can always prefix the query with the postgres comment string:

--select foo from bar;

and the query will not run but will be available in the psql deadline history buffer for editing.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.