pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Fuhr <mike@fuhr.org>
To: Robert Wimmer <seppwimmer@hotmail.com>
Cc: pgsql-interfaces@postgresql.org
Subject: Re: check foreign constraints before delete
Date: Wed, 21 Sep 2005 21:38:47 -0600
Message-ID: <20050922033847.GB90411@winnie.fuhr.org> (raw)
In-Reply-To: <BAY109-F12955AB36E2BB06F87D1D5D0940@phx.gbl>
References: <BAY109-F12955AB36E2BB06F87D1D5D0940@phx.gbl>

On Wed, Sep 21, 2005 at 11:43:23PM +0000, Robert Wimmer wrote:
> 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;

In PostgreSQL 8.0 you could use an EXCEPTION clause:

http://www.postgresql.org/docs/8.0/interactive/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPIN...

-- 
Michael Fuhr



view thread (2+ messages)

Message-ID: <20050922033847.GB90411@winnie.fuhr.org>
Permalink:  ../20050922033847.GB90411@winnie.fuhr.org/
Also on:    postgresql.org/message-id/20050922033847.GB90411@winnie.fuhr.org

 · 

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: mike@fuhr.org, seppwimmer@hotmail.com
  Subject: Re: check foreign constraints before delete
  In-Reply-To: <20050922033847.GB90411@winnie.fuhr.org>

* 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