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

Re: check foreign constraints before delete

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Robert Wimmer <seppwimmer(at)hotmail(dot)com>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: check foreign constraints before delete
Date: 2005-09-22 03:38:47
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-interfaces
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 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:

Michael Fuhr

In response to

pgsql-interfaces by date

Next:From: Ibrahim NoorzaieDate: 2005-09-22 06:13:31
Subject: where to get libpq for postgres 8 - please help!
Previous:From: Robert WimmerDate: 2005-09-21 23:43:23
Subject: check foreign constraints before delete

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