Waiting for 8.4 – \ef in psql

Today, Tom Lane committed patch, written by Abhijit Menon-Sen, which adds interesting feature to psql. Namely – it simplifies changing definition of functions.

Commit message pretty much explains everything:

Implement a psql command "\ef" TO edit the definition OF a FUNCTION.
IN support OF that, CREATE a backend FUNCTION pg_get_functiondef().
The psql command IS functional but maybe a bit rough around the edges...
 
Abhijit Menon-Sen

To elaborate a bit.

To change function definition before, you had to basically pg_dump -s the database, find the function, change it, and load to psql.

Other option was simply to keep creation.sql file, and modify it when you had to modify the function.

But now, it's simpler. It is enough to call \ef function_name, and your favorite $EDITOR will be launched, with full “CREATE OR REPLACE FUNCTION…" conveniently put in the edited buffer.

In case there is more than 1 function with given name, you will get nice error message:

# \ef texticlike
ERROR:  more than one FUNCTION named "texticlike"
LINE 1: SELECT 'texticlike'::pg_catalog.regproc::pg_catalog.oid
               ^

And, then you can use \ef with function params, like:

# \ef texticlike(citext, text)

Great addition. psql gets better and better.

2 thoughts on “Waiting for 8.4 – \ef in psql”

  1. Hi depesz, how about for overloaded functions?
    When i’m trying to use \ef and specifying an overloaded function it throws an error. ERROR: more than one function named “functionname”.

    Thanks!

Comments are closed.