Skip site navigation (1) Skip section navigation (2)

Questions about writing functions...

From: "Bob Whitehouse" <bwhitehouse(at)geeknest(dot)com>
To: "pgsql-novice" <pgsql-novice(at)postgresql(dot)org>
Subject: Questions about writing functions...
Date: 2001-04-19 21:23:18
Message-ID: 017501c0c916$f45134c0$a6a0fea9@amsite.com (view raw or flat)
Thread:
Lists: 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




Responses

pgsql-novice by date

Next:From: Bob WhitehouseDate: 2001-04-19 21:30:57
Subject: Questions about functions...
Previous:From: Peter EisentrautDate: 2001-04-19 15:47:58
Subject: Re: < Int4 - limit >

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group