pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Robert Wimmer <seppwimmer@hotmail.com>
To: pgsql-interfaces@postgresql.org
Subject: check foreign constraints before delete
Date: Wed, 21 Sep 2005 23:43:23 +0000
Message-ID: <BAY109-F12955AB36E2BB06F87D1D5D0940@phx.gbl> (raw)

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





view thread (2+ messages)  latest in thread

Message-ID: <BAY109-F12955AB36E2BB06F87D1D5D0940@phx.gbl>
Permalink:  ../BAY109-F12955AB36E2BB06F87D1D5D0940@phx.gbl/
Also on:    postgresql.org/message-id/BAY109-F12955AB36E2BB06F87D1D5D0940@phx.gbl

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: seppwimmer@hotmail.com
  Subject: Re: check foreign constraints before delete
  In-Reply-To: <BAY109-F12955AB36E2BB06F87D1D5D0940@phx.gbl>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox