Adding the optional clause 'AS' in CREATE TRIGGER

From: "Okano, Naoki" <okano(dot)naoki(at)jp(dot)fujitsu(dot)com>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Adding the optional clause 'AS' in CREATE TRIGGER
Date: 2016-11-15 01:44:04
Message-ID: 0B4917A40C80E34BBEC4BE1A7A9AB7E276EEDF@g01jpexmbkw05
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I would like to add the following support for a trigger.
This implementation enables to create a trigger efficiently
in single command.

It had been discussed before. The link is as shown below.
https://www.postgresql.org/message-id/CAA-aLv4m%3Df9cc1zcUzM49pE8%2B2NpytUDraTgfBmkTOkMN_wO2w%40mail.gmail.com

Currently, PostgreSQL requires two steps to create a trigger.
1. to create a function.
2. to define a trigger with action specified via already created function.

Supporting 'AS' clause in CREATE TRIGGER syntax will enable the option of
defining the trigger in single command.
As a bonus, it will be compatible with oracle.

Also, the optional clause 'OR REPLACE' is required as below.
https://www.postgresql.org/message-id/CAA-aLv6KYgVt2CwaRdcnptzWVngEm72Cp4mUFnF-MfeH0gS91g%40mail.gmail.com

Currently, to change the definition of a trigger, trigger needs to
be dropped first before creating it again with new definition.
To change the definition of a function in CREATE TRIGGER syntax,
trigger needs to be dropped first before creating it again with new definition, too!
So, we need to add the optional clause 'OR REPLACE'.

Adding the optional clauses 'AS' and 'OR REPLACE' in CREATE TRIGGER syntax gives
the comfort of defining the trigger or redefining the trigger definition
which contains the function definition in single command.

Here is the syntax based on the previous discussion.

CREATE [ OR REPLACE ] [ CONSTRAINT ] TRIGGER name { BEFORE | AFTER | INSTEAD OF }
{ event [ OR ... ] }
ON table_name
[ FROM referenced_table_name ]
[ NOT DEFERRABLE | [ DEFERRABLE ] { INITIALLY IMMEDIATE | INITIALLY DEFERRED } ]
[ FOR [ EACH ] { ROW | STATEMENT } ]
[ WHEN ( condition ) ]
{ EXECUTE PROCEDURE function_name ( arguments )
| AS 'trigger function definition' [ LANGUAGE lang_name ]
[ SET configuration_parameter { TO value | = value | FROM CURRENT }]
}

If you have your opinion on this concept, please give me it.

Regards,
Okano Naoki
Fujitsu

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Noah Misch 2016-11-15 02:17:31 Re: Pinning a buffer in TupleTableSlot is unnecessary
Previous Message Tsunakawa, Takayuki 2016-11-15 01:44:01 Re: Remove the comment on the countereffectiveness of large shared_buffers on Windows