From: | "Saltsgaver, Scott" <scottsa(at)aiinet(dot)com> |
---|---|
To: | "'pgsql-sql(at)postgresql(dot)org'" <pgsql-sql(at)postgresql(dot)org> |
Subject: | Reporting errors when a rule fails. |
Date: | 1999-09-28 20:40:43 |
Message-ID: | 7283DE19D141D111AD0E00A0C95B1955024886F9@mail2.aiinet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
I am currently design a database to be implemented on PostGreSQL 6.5.1. I
have two tables with the following schema:
create table1 ( myId : serial, status int4 );
create table2 ( myId : serial, parentId : int4, status );
I created a function that checks to make sure that a parent exists in
table1. Not sure if this is the best way, suggestions welcome.
create function parent_exists(int4) returns boolean as 'select
int4eq(count(*), 1) from table1 where table1.myId = $1' language 'sql'
I then created a rule to stop insertions into table2 if a parent does not
exists in table1.
create rule validate_parent_exists as on insert to table2 where
parent_exists(new.parentId) = false do instead nothing
Is there a way to return an error to the caller of an insert into table2
that a parent does not exists?
As mentioned, if there is a better way to implement this functionality,
please provide solutions. I am fairly new at SQL and PostGreSQL.
Thanks,
Scott Saltsgaver
Applied Innovation Inc.
scottsa(at)aiinet(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 1999-09-28 21:14:06 | Re: [SQL] Subselect performance |
Previous Message | Bruce Momjian | 1999-09-28 17:46:43 | Re: [SQL] table aliasing problem with 6.5... |