pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jon Horsman <horshaq@gmail.com>
To: chester c young <chestercyoung@yahoo.com>
Cc: sql pgsql <pgsql-sql@postgresql.org>
Subject: Re: Foreign Unique Constraint
Date: Thu, 29 Mar 2007 17:23:02 -0400
Message-ID: <4f4c2a010703291423y1fe42ff6rc425a78221f918a3@mail.gmail.com> (raw)
In-Reply-To: <415536.67726.qm@web54310.mail.yahoo.com>
References: <4f4c2a010703270621h5137a4e5rb515a9be9034a543@mail.gmail.com>
	<415536.67726.qm@web54310.mail.yahoo.com>

> use a pre-insert triggers - one for each table.  include something like

I ended up going this route and it seems to work.  Thanks for the help
from all. I figured i'd post the solution to the list so it shows up
when googled.  Also, if my solution can be simplfied i'd appreciate
knowing how.

This would be the trigger for table1 in my example.

CREATE FUNCTION function_name() RETURNS trigger AS '
        DECLARE
                result RECORD;
        BEGIN
                SELECT INTO result * FROM table2 WHERE extension=NEW.extension;
                IF FOUND THEN
                        RAISE EXCEPTION ''The extension % is already
in use'', NEW.extension;
                END IF;
                RETURN NEW;
        END;
' LANGUAGE plpgsql;

CREATE TRIGGER function_name BEFORE INSERT OR UPDATE ON table1 FOR
EACH ROW EXECUTE PROCEDURE function_name();

Again, thanks for the help.

Jon.



view thread (11+ messages)

Message-ID: <4f4c2a010703291423y1fe42ff6rc425a78221f918a3@mail.gmail.com>
Permalink:  ../4f4c2a010703291423y1fe42ff6rc425a78221f918a3@mail.gmail.com/
Also on:    postgresql.org/message-id/4f4c2a010703291423y1fe42ff6rc425a78221f918a3@mail.gmail.com

 · 

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-sql@postgresql.org
  Cc: horshaq@gmail.com, chestercyoung@yahoo.com
  Subject: Re: Foreign Unique Constraint
  In-Reply-To: <4f4c2a010703291423y1fe42ff6rc425a78221f918a3@mail.gmail.com>

* 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