[BioSQL-l] Postgres rules clarification

Rob Syme rob.syme at gmail.com
Tue Nov 15 03:24:29 UTC 2011


Hi all,

This may well be a basic query, my SQL experience isn't amazing.
The BioSQL tables have rules such as (in the ontology table, for example):

CREATE OR REPLACE RULE rule_ontology_i AS
    ON INSERT TO ontology
   WHERE (( SELECT ontology.ontology_id
           FROM ontology
          WHERE ontology.name::text = new.name::text)) IS NOT NULL DO
INSTEAD NOTHING;


It seems to me that this rule checks to make sure that the name field
is unique, failing quietly when there is a clash, but the uniqueness
of the ontology.name is already ensured by the table constraint:

CONSTRAINT ontology_name_key UNIQUE (name)

Have I misunderstood the purpose of the create/replace rule?

-r

Rob Syme



More information about the BioSQL-l mailing list