From: " <Miguel Sofer" <mig@utdt.edu>
To: pgsql-sql@postgresql.org
Subject: Rules and referential integrity
Date: Fri, 12 Nov 1999 12:13:55 -0300
Message-ID: <199911121513.MAA06784@ant.utdt> (raw)
I seem to have found a way to use the rule system for referential
integrity checks.
The manual says (in the "Rules vs Triggers part)
"It is possible, to place a qualified rule that rewrites a query to
NOTHING if the value of a column does not appear in another table. But
then the data is silently thrown away and that's not a good idea. If
checks for valid values are required, and in the case of an invalid
value an error message should be generated, it must be done by a
trigger for now."
Now: why not define a function (in pltcl; could be something else?)
create function err(bpchar) returns bpchar
as 'error $1' language 'pltcl'
Then, if the value of a column does not appear in another table, you
could rewrite the query to (for instance)
select err('your message')
This will raise a PGRES_FATAL_ERROR , with error message
ERROR: pltcl: your message
So: it is possible. Why it is better (or worse) than a trigger, I do
not know. Views on that?
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: Miguel Sofer" <mig@utdt.edu
Subject: Re: Rules and referential integrity
In-Reply-To: <199911121513.MAA06784@ant.utdt>
References: <199911121513.MAA06784@ant.utdt>
* 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