HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlModerate

How do I set the external editor for PostgreSQL's psql client?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgresqltheeditorpsqlclientforhowexternalset

Problem

What do I put in ~/.psqlrc file to set the default editor?

The editor I want to use (Textmate) is at /Users/username/bin/mate.

I found the place in the docs where they talk about it, and tried several syntax variations, but can't seem to get it to work.

For example, this didn't work...

\set PSQL_EDITOR "/Users/username/bin/mate"


In psql when I enter \e I get...

sh: /usr/local/bin/mate: No such file or directory
sh: line 0: exec: /usr/local/bin/mate: cannot execute: No such file or directory

Solution

Contrary to my comment above (which was the result of insufficient testing), you should put a line into .bashrc (or any similar place):

export PSQL_EDITOR="/Users/username/bin/mate"


In psql coming with PostgreSQL 9.2, there is a \setenv command, it is supposed to work from .psqlrc as well.

(Credits to Pedro Romano.)

Code Snippets

export PSQL_EDITOR="/Users/username/bin/mate"

Context

StackExchange Database Administrators Q#20127, answer score: 15

Revisions (0)

No revisions yet.