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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-novice by date

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