This approach has one definite disadvantage. PostgreSQL 12.1, compiled by Visual C++ build 1914, 64-bit $ SET PSQL_EDITOR=C:\Program Files\Sublime Text 3\sublime_text.exe Of course, we may use just sublime_text.exe:
It’s quoted by default before execution on Windows. You can see now why we cannot include any arguments in the PSQL_EDITOR. * severe brain damage in their command shell plus the fact that standardĮditorName, editor_lineno_arg, lineno, fname) But this policy is not very workable on Windows, due to * switches, eg, EDITOR="pico -t" it's up to the user to put quotes in it * On Unix the EDITOR value should *not* be quoted, since it might include Let’s try to examine psql sources, to know if we can pass arbitrary command line into: The only additional parameter that can be passed is PSQL_EDITOR_LINENUMBER_ARG. '"C:\Program Files\Sublime Text 3\subl.exe -w"' is not recognized asĪn internal or external command, operable program or batch file. $ SET PSQL_EDITOR=C:\Program Files\Sublime Text 3\subl.exe -w Specifying -w will cause the subl command to not exit until the file is closed.īut the problem is we cannot pass additional parameters in Windows: When you’re trying to execute \e next time, is reports about temp file existence. So psql gets signal about subl finishes and returns, but the temp file wasn’t even edited yet. But subl is just a special tool, which in fact launches sublime.exe and then just dies. Psql runs editor and then waits for the editor process to finish. This can be used to open files and projects in Sublime Text, and also works as an EDITOR for unix tools, such as git and subversion.
Sublime Text includes a command line tool, subl, to work with files on the command line. What’s wrong here? First of all, I’ve used subl.exe instead of sublime.exe which is special command line tool: $ SET PSQL_EDITOR=C:\Program Files\Sublime Text 3\subl.exeĬould not open temporary file "C:\Temp\": File existsĪs you can see nothing was executed after the first \e command, even though I’ve edited and saved the content of the query. Let’s try to set the environment variable then.
it will restore the unsaved files on startup.Īccording to the manual PSQL_EDITOR, EDITOR and VISUAL are environment variables, which are used inside psql to call an editor for input. I’ve chosen Sublime as a target because it’s not a simple console or single window application, but rather an advanced text processor with enhanced file handling, e.g. After LinkedIn, GitHub, and Citus, you cannot be sure anymore! ?
Who knows what the next purchase of Microsoft will be. If you, my dear reader, are a Linux user, I’m sure you will also find this information useful anyway. Still, there is a lack of such tips for Windows users. There is a lots of information about tweaking psql in POSIX environments.
All tests done on Windows 10 with PostgreSQL 12 installed.Īs you know, PostgreSQL ships with an interactive console tool named psql, which allows you to use a lot of enhanced features, like watching, for example.
While trying to figure out all possible pitfalls, I’ve decided to write a full blog post. This supposed to be just a short TIL entry about PSQL_EDITOR variable.