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

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: Foreign Unique Constraint



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.



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group