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?
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.
After the editor exits, type \p
to see what the editor put back into the query buffer.
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.
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.