Trigger before insert - Mailing list pgsql-general

From ON.KG
Subject Trigger before insert
Date
Msg-id 9414883125.20041125143740@on.kg
Whole thread Raw
In response to Re: [PERFORM] HELP speed up my Postgres  (Klint Gore <kg@kgb.une.edu.au>)
Responses Re: Trigger before insert
List pgsql-general
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!


pgsql-general by date:

Previous
From: juleni@livetrade.cz
Date:
Subject: VACUUM ANALYZE question - PostgreSQL performance tests
Next
From: "Net Virtual Mailing Lists"
Date:
Subject: why use SCHEMA? any real-world examples?