Re: Foreign Unique Constraint - Mailing list pgsql-sql

From Jon Horsman
Subject Re: Foreign Unique Constraint
Date
Msg-id 4f4c2a010703291423y1fe42ff6rc425a78221f918a3@mail.gmail.com
Whole thread Raw
In response to Re: Foreign Unique Constraint  (chester c young <chestercyoung@yahoo.com>)
List pgsql-sql
> 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
RAISEEXCEPTION ''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.


pgsql-sql by date:

Previous
From: "Rajesh Kumar Mallah"
Date:
Subject: Re: Track query status
Next
From: Kyle Bateman
Date:
Subject: Re: olympics ranking query