Trigger before insert

From: "ON(dot)KG" <skyer(at)on(dot)kg>
To: pgsql-general(at)postgresql(dot)org
Subject: Trigger before insert
Date: 2004-11-25 11:37:40
Message-ID: 9414883125.20041125143740@on.kg
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-performance

Hi all,

===================================
CREATE FUNCTION trigger_test_func()
RETURNS trigger
AS '
DECLARE
cnt int4;

BEGIN
SELECT INTO cnt COUNT(*)
FROM table_test
WHERE ip = new.ip;

IF cnt > 50 THEN
-- THERE THE "INSERT" HAS TO BE STOPED
END IF;

RETURN new;
END;'
LANGUAGE 'plpgsql';

CREATE TRIGGER trigger_test
BEFORE INSERT
ON table_test
FOR EACH ROW
EXECUTE PROCEDURE trigger_test_func();
===================================

How could i stop Inserting record into table by some condition?

Thanx!

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Robert Soeding 2004-11-25 12:18:12 Re: Benchmark-Comparison PostGreSQL vs. SQL Server
Previous Message Richard Huxton 2004-11-25 11:34:21 Re: Benchmark-Comparison PostGreSQL vs. SQL Server

Browse pgsql-performance by date

  From Date Subject
Next Message Dave Cramer 2004-11-25 12:38:23 Re: Postgres vs. MySQL
Previous Message Anatoly Okishev 2004-11-25 09:21:00 Re: HELP speed up my Postgres