Re: Adding the optional clause 'AS' in CREATE TRIGGER

From: "Okano, Naoki" <okano(dot)naoki(at)jp(dot)fujitsu(dot)com>
To: "Okano, Naoki" <okano(dot)naoki(at)jp(dot)fujitsu(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Adding the optional clause 'AS' in CREATE TRIGGER
Date: 2017-02-07 08:11:17
Message-ID: 0B4917A40C80E34BBEC4BE1A7A9AB7E27A631D@g01jpexmbkw05
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wednesday, November 16, 2016 4:31 PM Okano Naoki wrote:
> > But in any case it would be a serious mistake to do this without first
> > implementing CREATE OR REPLACE TRIGGER. I think that's an entirely separate
> > proposal and you would be well advised to treat it as such.
> I see. There are more problems than I expected...
> Let me start with 'OR REPLACE' clause.
I tried to cretae a patch for CREATE OR REPLACE TRIGGER.
An example of execution is shown below.

example)
1.define a new trigger
CREATE TRIGGER regular_trigger
AFTER UPDATE ON table_name
REFERENCING OLD TABLE AS oldtable_1 NEW TABLE AS newtable_1
FOR EACH STATEMENT
EXECUTE PROCEDURE func_1();
2.redinfe a trigger in single command
CREATE OR REPLACE TRIGGER regular_trigger
AFTER UPDATE OR DELETE ON table_name
REFERENCING OLD TABLE AS oldtable_2 NEW TABLE AS newtable_2
FOR EACH ROW
EXECUTE PROCEDURE func_2();

If the named trigger does not exist.
a new trigger is also created by using OR REPLACE clause.
A regular trigger cannot be replaced by a constraint trigger and vice varsa.
because a constraint trigger has a different role from regular triger.

Please give me feedback.

Regards,
Okano Naoki
Fujitsu

Attachment Content-Type Size
OR_REPLACE_for_CREATE_TRIGGER_v1.patch application/octet-stream 29.4 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ideriha, Takeshi 2017-02-07 08:59:03 Re: [WIP] RE: DECLARE STATEMENT setting up a connection in ECPG
Previous Message Fabien COELHO 2017-02-07 07:36:29 Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless)