Reputation: 4867
wondering around psql.
postgres-# \ev staff_list 2
environment variable PSQL_EDITOR_LINENUMBER_ARG must be set to specify a line number
https://www.postgresql.org/docs/current/app-psql.html#APP-PSQL-PATTERNS
as the psql cli shows, in order to execute \ev staff_list 2
I need know about PSQL_EDITOR_LINENUMBER_ARG.
But I don't know how to set environment variable: PSQL_EDITOR_LINENUMBER_ARG.
So how to make \ev staff_list 2
works in windows?
Upvotes: 1
Views: 234
Reputation: 3034
I hit this in Linux, too (Ubuntu, to be specific).
@Laurenz Albe is spot on with the solution; just a few more points I think might be worth adding.
Using \ef
with [ line_number ]
is the only reliable way I have found to actually get to the line causing the problem. If I jump to line 39 in my (vim) editor, I'm usually a few lines too early1. So, I've found it invaluable.
From within psql, you can just use psql's \setenv
\setenv PSQL_EDITOR_LINENUMBER_ARG "+"
In psql 13.9, if you don't have PSQL_EDITOR
set, you get a list of options:
Select an editor. To change later, run 'select-editor'.
1 /usr/bin/nedit
2 /bin/nano <---- easiest
3 /usr/bin/vim.basic
4 /usr/bin/vim.tiny
5 /usr/bin/emacs
6 /bin/edChoose 1-6 [2]: 3
So, it will default to nano
if you're not paying close attention, and wanted vim.
When you \q
uit vim, you are at the continuation-line prompt (->
). A semicolon will run the function as you just edited it; ctrl-c will abort. (Usual psql behavior, but not quite intuitive after the \ef
finishes.)
Upvotes: 0
Reputation: 247320
PostgreSQL defines a default editor in src/bin/psql/settings.h
: for Windows, that is notepad.exe
, everywhere else it is vi
.
Now vi
has an option to start the editor with the cursor on a certain line:
vi +10 myfile
But notepad.exe
has no such option, hence the error message.
You have two things you can do:
don't try to place the cursor on a specific line in the editor:
\ev staff_list
Use a different editor and tell it how to position the cursor:
SET PSQL_EDITOR=vim.exe
SET PSQL_EDITOR_LINENUMBER_ARG="+"
psql -c "\ev staff_list 2"
Upvotes: 2