Thread: Proposal - Support for 'OR REPLACE' in 'CREATE TRIGGER' command

Proposal - Support for 'OR REPLACE' in 'CREATE TRIGGER' command

From
"Prabakaran, Vaishnavi"
Date:
<div class="WordSection1"><p class="MsoNormal">Hi,<p class="MsoNormal"> <p class="MsoNormal">This is a proposal to
implementsupport for 'OR REPLACE' in 'CREATE TRIGGER' command as an optional clause. <p class="MsoNormal"> <p
class="MsoNormal">Theaim of this proposal is to present a way to support replace trigger functionality. <p
class="MsoNormal">Addingthe optional clause ‘OR REPLACE’ in CREATE TRIGGER syntax gives users the option of redefining
thetrigger in single command. <p class="MsoNormal">And such support will be helpful for customers when they are
migratingfrom other RDBMs, which already has this support in-built.<p class="MsoNormal"> <p class="MsoNormal">As
PostgreSQLsupports 'OR REPLACE' in various commands such as CREATE VIEW, CREATE FUNCTION, CREATE LANGUAGE, CREATE
RULE, implementing this support to 'CREATE TRIGGER'  command also will be useful for different migration/schema upgrade
scripts.<pclass="MsoNormal"> <p class="MsoNormal">[Brief Design]<p class="MsoNormal">Brief design of 'OR REPLACE'
supportin 'CREATE TRIGGER' implementation is presented below:<p class="MsoNormal" style="text-indent:36.0pt">- Updating
parserrules to support 'OR REPLACE' as an optional clause in the syntax of 'CREATE TRIGGER' command.<p
class="MsoNormal"style="text-indent:36.0pt">- Support to update existing trigger's system table(pg_trigger) record with
newdefinition.<p class="MsoNormal" style="text-indent:36.0pt">- Support to update existing trigger's dependencies(which
thetrigger depends on)based on new trigger definition. <p class="MsoNormal" style="text-indent:36.0pt">- Following the
existingsystem behaviour of other commands that supports 'OR REPLACE' functionality, any dependent object should not be
droppedwhile replacing the trigger. <p class="MsoNormal" style="margin-left:42.75pt">Only identified dependent object
isthe constraint object, created for constraint trigger. When the constraint trigger is replaced by regular trigger, to
avoidhaving constraint object still tagged to regular trigger, a new condition will be enforced to restrict replacing
constrainttrigger with regular trigger and vice-versa.  Any attempt to replace between regular and constraint triggers
displaysnew error messages. <p class="MsoNormal"> <p class="MsoNormal"> <p class="MsoNormal">I can start working on a
patchbased on the above.<p class="MsoNormal"><span style="mso-fareast-language:EN-AU"> </span><p
class="MsoNormal"><spanstyle="mso-fareast-language:EN-AU">Thanks & Regards,</span><p class="MsoNormal"><span
style="mso-fareast-language:EN-AU">Vaishnavi</span><pclass="MsoNormal"> </div>