Questions about writing functions... - Mailing list pgsql-novice

From Bob Whitehouse
Subject Questions about writing functions...
Date
Msg-id 017501c0c916$f45134c0$a6a0fea9@amsite.com
Whole thread Raw
Responses Re: Questions about writing functions...  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-novice
If I write a function that deletes a record from a table, how do I access
the output from the delete operation to see if it completed successfully?
Check out the IF statement below.

CREATE FUNCTION del_test(INT4)
        RETURNS INT4
        AS 'DECLARE
                int_input         ALIAS FOR $1;
                int_success    INT4;

            BEGIN
                int_success := 0;
                DELETE FROM table WHERE id = int_input;
                IF (output from delete operation = 1) THEN
                    int_success := 1
                END IF;
            RETURN int_success;
            END;'
LANGUAGE 'plpgsql';

I'm also wondering if I need to be able to trap an error and rollback the
state of the database. If so, how would I do it?
I've seen it done like this in other databases before:

EXEC SQL WHENEVER SQLERROR ROLLBACK ABORT;

Thanks, Bob




pgsql-novice by date:

Previous
From: "Bob Whitehouse"
Date:
Subject: looping through records
Next
From: "Bob Whitehouse"
Date:
Subject: Questions about functions...