| From: | Rory Campbell-Lange <rory(at)campbell-lange(dot)net> |
|---|---|
| To: | Nathaniel Trellice <naptrel(at)yahoo(dot)co(dot)uk> |
| Cc: | pgsql-novice(at)postgresql(dot)org |
| Subject: | Re: Conditionally executing multiple statements in series as single SQL statement |
| Date: | 2009-12-18 13:18:45 |
| Message-ID: | 20091218131845.GD22707@campbell-lange.net |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-novice |
On 18/12/09, Nathaniel Trellice (naptrel(at)yahoo(dot)co(dot)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(at)campbell-lange(dot)net
Campbell-Lange Workshop
www.campbell-lange.net
0207 6311 555
3 Tottenham Street London W1T 2AF
Registered in England No. 04551928
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Oliveiros C, | 2009-12-18 13:45:24 | Re: Conditionally executing multiple statements in series as single SQL statement |
| Previous Message | Sean Davis | 2009-12-18 13:16:33 | Re: Conditionally executing multiple statements in series as single SQL statement |