pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Saltsgaver, Scott <scottsa@aiinet.com>
To: 'pgsql-sql@postgresql.org' <pgsql-sql@postgresql.org>
Subject: Reporting errors when a rule fails.
Date: Mon, 11 Oct 1999 16:20:55 -0400
Message-ID: <7283DE19D141D111AD0E00A0C95B19550248870E@mail2.aiinet.com> (raw)

I have posted this question in the past and did not receive a response.

> Reporting errors when a rule fails.
> 
> I am currently design a database to be implemented using 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 );
> 
parentId is a foreign key into table1.

> 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 reject 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, who attempted the insert
> into table2 where the parent does not exists in table1?
> 
> As mentioned, if there is a better way to implement this functionality,
> suggestions are welcome.
> 
> Thanks,
> Scott Saltsgaver
> Applied Innovation Inc.
> scottsa@aiinet.com



view thread (2+ messages)

Message-ID: <7283DE19D141D111AD0E00A0C95B19550248870E@mail2.aiinet.com>
Permalink:  ../7283DE19D141D111AD0E00A0C95B19550248870E@mail2.aiinet.com/
Also on:    postgresql.org/message-id/7283DE19D141D111AD0E00A0C95B19550248870E@mail2.aiinet.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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: scottsa@aiinet.com
  Subject: Re: Reporting errors when a rule fails.
  In-Reply-To: <7283DE19D141D111AD0E00A0C95B19550248870E@mail2.aiinet.com>
  References: <7283DE19D141D111AD0E00A0C95B19550248870E@mail2.aiinet.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