pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: cnliou@eurosport.com
To: pgsql-sql@postgresql.org
Subject: Limit A Table To 1 Row
Date: Wed, 7 Aug 2002 03:29:50 GMT
Message-ID: <200208070329.32fc@th00.opsion.fr> (raw)

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








view thread (4+ messages)  latest in thread

Message-ID: <200208070329.32fc@th00.opsion.fr>
Permalink:  ../200208070329.32fc@th00.opsion.fr/
Also on:    postgresql.org/message-id/200208070329.32fc@th00.opsion.fr

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: cnliou@eurosport.com
  Subject: Re: Limit A Table To 1 Row
  In-Reply-To: <200208070329.32fc@th00.opsion.fr>

* 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