vendredi 10 janvier 2020

Check function with IF statement in POSTGRESQL

I have 10 functions, all 10 return '1' if the function has no errors and '0' if function has errors. I want to create another function witch calls all this functions and which checks it out if the functions return 0 or 1. After that, I want to run this function in linux crontab and the function's output (some text from if conditions) to go in a log file. I'm not sure if I can check this functions like this. Thanks for your time!

CREATE OR REPLACE FUNCTION public.test_al1()
    RETURNS text
    LANGUAGE 'plpgsql'
    COST 100 

AS $BODY$
DECLARE

BEGIN
    select public.test();
    if (select public.test()) = 1 then
        RAISE NOTICE 'No errors'
    else
        RAISE NOTICE 'Errors'
    end if;

END 
$BODY$;

Aucun commentaire:

Enregistrer un commentaire