Postgres on the command line with external editor not running query

▼魔方 西西 提交于 2019-12-22 09:36:52

问题


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?


回答1:


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.



回答2:


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




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/20071309/postgres-on-the-command-line-with-external-editor-not-running-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!