Received: from orion.SAPserv.Hamburg.dsh.de (Tpolaris2.sapham.debis.de [53.2.131.8]) by hub.org (8.9.3/8.9.3) with SMTP id LAA74531 for ; Fri, 12 Nov 1999 11:22:25 -0500 (EST) (envelope-from wieck@debis.com) Received: by orion.SAPserv.Hamburg.dsh.de for pgsql-sql@postgreSQL.org id m11mJKg-0003kLC; Fri, 12 Nov 99 17:13 MET Message-Id: From: wieck@debis.com (Jan Wieck) Subject: Re: [SQL] Rules and referential integrity To: mig@utdt.edu Date: Fri, 12 Nov 1999 17:13:50 +0100 (MET) Cc: pgsql-sql@postgreSQL.org Reply-To: wieck@debis.com (Jan Wieck) In-Reply-To: <199911121528.MAA07053@ant.utdt> from "hub.org!owner-pgsql-sql" at Nov 12, 99 12:13:55 pm X-Mailer: ELM [version 2.4 PL25] Content-Type: text > 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? Depends on the data and usage. If only few tuples are affected by a statement, a trigger will usually do a better job. Especially if the path to find that tuple is very complicated, because the rule has to follow this path another time. OTOH if one statement affects thousands of rows, a rule will perform better because it is executed in one internal extra query instead of invoking the trigger for each single tuple. There is no general "this is better than that". Jan -- #======================================================================# # It's easier to get forgiveness for being wrong than for being right. # # Let's break this rule - forgive me. # #========================================= wieck@debis.com (Jan Wieck) #