Limit A Table To 1 Row - Mailing list pgsql-sql

From
Subject Limit A Table To 1 Row
Date
Msg-id 200208070329.32fc@th00.opsion.fr
Whole thread Raw
Responses Re: Limit A Table To 1 Row  (Bruno Wolff III <bruno@wolff.to>)
Re: Limit A Table To 1 Row  ("Josh Berkus" <josh@agliodbs.com>)
List pgsql-sql
Hello!

Corporate table, t1, should contain exact 1 row.
I strongly believe that there are cleaner versions
than the following combination of trigger and rule.

Thank you in advance for any improved version!

CNLIOU
--------

CREATE TABLE t1 (CorpId TEXT,CorpName TEXT);

CREATE FUNCTION f1() RETURNS OPAQUE AS '
DECLARE rc SMALLINT;
BEGIN SELECT COUNT(*) INTO rc FROM t1;
 IF rc > 0 THEN   RETURN NULL; END IF;
 RETURN NEW;
END;' LANGUAGE 'plpgsql';

CREATE TRIGGER trigger1 BEFORE INSERT ON t1 FOR EACH
ROW EXECUTE PROCEDURE f1();

CREATE RULE rule1 AS ON DELETE TO t1 DO INSTEAD
NOTHING;

--------------------------------------------------------
You too can have your own email address from Eurosport.
http://www.eurosport.com







pgsql-sql by date:

Previous
From: "Christopher Kings-Lynne"
Date:
Subject: Re: ALTER TABLE follow up
Next
From: Tom Lane
Date:
Subject: Re: SQL syntax