2

I want to get the functions and trigger functions separately, with sql from JDBC, not command line.

update:
Sorry, it's not clear enough. I mean, trigger function is also a function. how can I tell a trigger function from normal function with sql?

As far as I know is, trigger function's return type is trigger, is it enough to use this to distinguish?

Thanks.

1
  • It's not clear what you are asking. Try to provide some more explanations and maybe an example Commented May 8, 2014 at 6:31

3 Answers 3

9

To get the function source:

select pg_get_functiondef('public.your_trigger_function()'::regprocedure);

To get the trigger definition

select pg_get_triggerdef(oid)
from pg_trigger
where tgname = 'name_of_your_trigger';
Sign up to request clarification or add additional context in comments.

Comments

1

You can get all user-defined functions with the SQL below. *The doc explains information_schema.routines:

SELECT routine_name 
FROM information_schema.routines 
WHERE routine_type IS DISTINCT FROM 'PROCEDURE'
AND specific_schema != 'pg_catalog'
AND specific_schema != 'information_schema';

Or:

SELECT routine_name 
FROM information_schema.routines 
WHERE (routine_type != 'PROCEDURE' OR routine_type IS NULL)
AND specific_schema != 'pg_catalog'
AND specific_schema != 'information_schema';

And, you can get all user-defined trigger functions with the SQL below:

SELECT routine_name 
FROM information_schema.routines 
WHERE data_type = 'trigger' AND specific_schema != 'pg_catalog';

Comments

0
    select tgname, 
       pg_get_triggerdef(oid),
       CASE 
            WHEN split_part(pg_get_triggerdef(oid), 'FUNCTION', 2) IS NOT NULL 
                THEN pg_get_functiondef(split_part(pg_get_triggerdef(oid), 'FUNCTION', 2) ::regprocedure)   
            ELSE pg_get_functiondef(split_part(pg_get_triggerdef(oid), 'PROCEDURE', 2) ::regprocedure)  
       END
from pg_trigger
where tgname = 'test_updated';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.