check foreign constraints before delete

From: "Robert Wimmer" <seppwimmer(at)hotmail(dot)com>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: check foreign constraints before delete
Date: 2005-09-21 23:43:23
Message-ID: BAY109-F12955AB36E2BB06F87D1D5D0940@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

hi,

i want to write a function in plpgsql, which checks a foreign key constraint
violation on deleting a special value in my table. for example

CREATE TABLE to (n NAME PRIMARY KEY);
CREATE TABLE t1 (n_name NAME REFERENCES to(n), id INTEGER ...);

CREATE FUNCTION check_before_delete(..some value ...) RETURNS INTEGER AS '
..
IF foreign_key_violation THEN RETURN -1 END IF;
RETURN 0;
..
END;
...

so i can avoid the database errormessages.

i checked some 'd' commands with the 'E' option. but i have no idea for a
smart solution of this problem

thanx in advance (tom?)

sepp

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Michael Fuhr 2005-09-22 03:38:47 Re: check foreign constraints before delete
Previous Message Michael Fuhr 2005-09-20 22:03:23 Re: finding indexed functions from pg_index