Function for more readable function source code - Mailing list pgsql-general

From Kenneth Tanzer
Subject Function for more readable function source code
Date
Msg-id 47ED861E.2040301@desc.org
Whole thread Raw
List pgsql-general
The only way I knew to display the source code of a function was with
\df+, which produces very hard-to-read output, because it returns
several columns about the function, but usually all I want is the source.

So I "created" a function (i.e., shameless copied the psql interpreter)
to display just the source code, which makes it much more readable.  I'm
passing it along in case it's useful to others as well.

Ken

CREATE FUNCTION function_source( char ) RETURNS text AS $$
DECLARE
    funcname ALIAS FOR $1;
    source TEXT;

BEGIN

    SELECT INTO source replace(p.prosrc,E'\x09',' ')
    FROM pg_catalog.pg_proc p
        LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
        LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang
        JOIN pg_catalog.pg_roles r ON r.oid = p.proowner
    WHERE p.prorettype <> 'pg_catalog.cstring'::pg_catalog.regtype
        AND (p.proargtypes[0] IS NULL
        OR   p.proargtypes[0] <> 'pg_catalog.cstring'::pg_catalog.regtype)
        AND NOT p.proisagg
        AND p.proname ~ ( '^(' || funcname || ')$' )
        AND pg_catalog.pg_function_is_visible(p.oid) ;
    RETURN source;
END;$$ language 'plpgsql';




pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Out of memory
Next
From: Ivan Sergio Borgonovo
Date:
Subject: general optimisation rule for slice of table frequently accessed.