Amit Erandole
Amit Erandole

Reputation: 12271

Postgres on the command line with external editor not running query

When I run \e on the command line while logged into the psql command line tool, my default editor, sublime text, duitifully opens. However, when I type in a query like this:

create table tutorials (
  tutorial_id serial primary key,
  title text,

  author_id integer references authors(author_id)

);

Then hit save and exit, nothing happens! My query is not run. What am I doing wrong? How do I fix this?

Upvotes: 4

Views: 2982

Answers (4)

Viktor Nonov
Viktor Nonov

Reputation: 1512

After explicitly setting the PSQL_EDITOR variable it works on macOS Sierra/vim 8/psql 9.4.5

export PSQL_EDITOR="vim"

If you want to make the setting persistent add it to the ~/.profile

PS: Although psql seemed to open vim before setting PSQL_EDITOR I was experiencing the same problem as the OP.

Upvotes: 0

Peter Dolan
Peter Dolan

Reputation: 43

Stumbled upon this while experiencing a similar problem, nothing here helped. Eventually tried it with another editor (nano) which seemed to fix it. From there, I nuked my vimrc and added everything back. Strangely enough, that seemed to fix it. Thread here.

Upvotes: 0

Molly Schwarz
Molly Schwarz

Reputation: 41

I had a similar problem until I added the -w switch to export EDITOR.

From http://www.sublimetext.com/docs/3/osx_command_line.html:

  • To use Sublime Text as the editor for many commands that prompt for input, set your EDITOR environment variable:
  • export EDITOR='subl -w'
  • Specifying -w will cause the subl command to not exit until the file is closed.

Upvotes: 4

Peter Eisentraut
Peter Eisentraut

Reputation: 36729

After the editor exits, type \p to see what the editor put back into the query buffer.

Upvotes: 2

Related Questions