How do I set the external editor for PostgreSQL's psql client?
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.)