pg.ddx.io pgsql-performance@postgresql.org mailing list archive
help / color / mirror / Atom feedTrigger before insert
3+ messages / 2 participants
[nested] [flat]
* Trigger before insert
@ 2004-11-25 11:37 ON.KG <skyer@on.kg>
0 siblings, 1 reply; 3+ messages in thread
From: ON.KG @ 2004-11-25 11:37 UTC (permalink / raw)
To: pgsql-general@postgresql.org
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!
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Trigger before insert
@ 2004-11-25 12:54 Richard Huxton <dev@archonet.com>
parent: ON.KG <skyer@on.kg>
0 siblings, 1 reply; 3+ messages in thread
From: Richard Huxton @ 2004-11-25 12:54 UTC (permalink / raw)
To: ON.KG <skyer@on.kg>; +Cc: pgsql-general@postgresql.org
ON.KG wrote:
>
> How could i stop Inserting record into table by some condition?
RETURN null when using a before trigger. Or raise an exception to abort
the whole transaction.
--
Richard Huxton
Archonet Ltd
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Trigger before insert
@ 2004-11-25 15:02 ON.KG <skyer@on.kg>
parent: Richard Huxton <dev@archonet.com>
0 siblings, 0 replies; 3+ messages in thread
From: ON.KG @ 2004-11-25 15:02 UTC (permalink / raw)
To: Richard Huxton <dev@archonet.com>; +Cc: pgsql-general@postgresql.org
Hi!
>> How could i stop Inserting record into table by some condition?
RH> RETURN null when using a before trigger. Or raise an exception to abort
RH> the whole transaction.
Thanx ;)
RETURN NULL works so as i need
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2004-11-25 15:02 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-11-25 11:37 Trigger before insert ON.KG <skyer@on.kg>
2004-11-25 12:54 ` Richard Huxton <dev@archonet.com>
2004-11-25 15:02 ` ON.KG <skyer@on.kg>
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