Re: Conditionally executing multiple statements in series as single SQL statement - Mailing list pgsql-novice

From Rory Campbell-Lange
Subject Re: Conditionally executing multiple statements in series as single SQL statement
Date
Msg-id 20091218131845.GD22707@campbell-lange.net
Whole thread Raw
In response to Conditionally executing multiple statements in series as single SQL statement  (Nathaniel Trellice <naptrel@yahoo.co.uk>)
List pgsql-novice
On 18/12/09, Nathaniel Trellice (naptrel@yahoo.co.uk) wrote:
> In other words, later statements will only be executed if all before
> them have 'gone well'. When a statement 'fails', no further
> expressions are executed.. The variable 'status' is non-zero if, and
> only if, all four things were successfully executed.

You could do something along the following lines:

CREATE OR REPLACE FUNCTION
    fn_test ( integer) RETURNS INTEGER
    AS $$
    DECLARE
        input    ALIAS   for $1;
        status   INTEGER := 0;
        returner INTEGER := 0;
    BEGIN
        PERFORM fn_test1 (input);
        IF NOT FOUND THEN
            RETURN returner;
        ELSE
           SELECT INTO status * FROM fn_test2 (input);
           IF status != 1 THEN
                RAISE NOTICE 'status from fn_test2 not expected %' % status
                RETURN returner;
           ELSE
                ...etc...
           END IF;
           returner = 1
           RETURN returner;
        END IF;
END;$$
    LANGUAGE plpgsql;

-
Rory Campbell-Lange
Director
rory@campbell-lange.net

Campbell-Lange Workshop
www.campbell-lange.net
0207 6311 555
3 Tottenham Street London W1T 2AF
Registered in England No. 04551928

pgsql-novice by date:

Previous
From: Sean Davis
Date:
Subject: Re: Conditionally executing multiple statements in series as single SQL statement
Next
From: "Oliveiros C,"
Date:
Subject: Re: Conditionally executing multiple statements in series as single SQL statement