Trigger with WHEN clause (WIP)

From: Itagaki Takahiro <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Trigger with WHEN clause (WIP)
Date: 2009-10-15 09:26:15
Message-ID: 20091015182143.A2E2.52131E4D@oss.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I'm working on WHEN clause support in triggers.
I heard that the feature is in the SQL standard.

We can rewrite triggers that uses suppress_redundant_updates_trigger
http://www.postgresql.org/docs/8.4/static/functions-trigger.html
with WHEN clause:
CREATE TRIGGER modified_any
BEFORE UPDATE ON tbl
FOR EACH ROW
WHEN (OLD.* IS DISTINCT FROM NEW.*)
EXECUTE PROCEDURE trigger_func();

I think there is a benefit to provide WHEN cluase at least
for compatibility with other DBMSs, even through we can move
the expressions into the body of trigger functions.

WIP-patch attached. It adds 'tgqual' text field into pg_trigger.
It works at first glance, but surely needs some adjustments
especially in the usage of TupleTableSlot in TriggerEnabled().

I have a question about executing qualification expression.
I used ecxt_innertuple for old tuples and ecxt_outertuple
for new tuples, but I'm not sure it is the right way.
Comments and suggestions welcome.

James Pye <lists(at)jwp(dot)name> wrote:
> Well, looks like WHEN is, or is going to be standard:
>
> <triggered action> ::=
> [ FOREACH { ROW | STATEMENT } ]
> [ WHEN<left paren><search condition> <right paren> ]
> <triggered SQL statement>
>
> (page 653 from 5CD2-02-Foundation-2006-01)

David Fetter <david(at)fetter(dot)org> wrote:
> Page 674 of 6WD_02_Foundation_2007-12 has a similar thing:
>
> <triggered action> ::=
> [ FOR EACH { ROW | STATEMENT } ]
> [ <triggered when clause> ]
> <triggered SQL statement>
>
> <triggered when clause> ::=
> WHEN <left paren> <search condition> <right paren>

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center

Attachment Content-Type Size
trigger-when_20091015.patch application/octet-stream 40.7 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message mingsoftt 2009-10-15 09:44:43 visual c++ compile error when included spi.h and trigger.h
Previous Message Heikki Linnakangas 2009-10-15 08:34:30 Re: Hot standby status