Search code examples
windowspostgresqlpsql

How to use PSQL_EDITOR_LINENUMBER_ARG in Windows version of postgresql


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?


Solution

  • 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:

    1. don't try to place the cursor on a specific line in the editor:

      \ev staff_list
      
    2. 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"