Re: AW: AW: [HACKERS] Rule system - Mailing list pgsql-hackers

From jwieck@debis.com (Jan Wieck)
Subject Re: AW: AW: [HACKERS] Rule system
Date
Msg-id m0z7EMu-000EBPC@orion.SAPserv.Hamburg.dsh.de
Whole thread Raw
In response to Re: AW: AW: [HACKERS] Rule system  (Vadim Mikheev <vadim@krs.ru>)
List pgsql-hackers
>
> Jan Wieck wrote:
> >
> >     It might look like:
> >
> >         create trigger mytrig before insert or update on mytab
> >             for each row do (
>                            ^^
> Why not EXECUTE ?

    Just  to indicate that this time a function body, for which a
    trigger function has  to  be  created  on  the  fly,  follows
    instead of the name of an existing function to be called.

    But  for  bison  it  should  be  no problem to decide whether
    EXECUTE PROCEDURE proname(args) or EXECUTE  PROCEDURE  (body)
    is used.  I don't really care about the final syntax.

>
> >                 begin
> >                     new.lastupdate := 'now';
> >                     return new;
> >                 end;
> >             ) language 'plpgsql';
> >
> >     This  would be easy. Just an enhancement to the parser and to
> >     the create trigger  utility  processing  so  it  creates  the
> >     required  function  on  the fly. Modification of new, raising
> >     errors via elog() and suppressing  the  operation  itself  by
> >     returning  NULL  is  already there in PL/pgSQL. We would need
> >     something smart for the functions  name,  because  using  the
>       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >     trigger  name  only  would  break  the current possibility to
>       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >     define  the  same  trigger  name  on  different  tables  with
>       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >     different actions. Something like __trig_<oid> would be good.
>       ^^^^^^^^^^^^^^^^^
> I missed here. What did you mean?

    What I have in mind for

        CREATE TRIGGER ... EXECUTE PROCEDURE (body)

    is,  that  this  time  a  trigger  function  is automatically
    created before the usual trigger is defined. For the function
    there  is  a  name  required.   Currently  the  following  is
    possible:

        CREATE TRIGGER on_insert AFTER INSERT on emp
            FOR EACH ROW EXECUTE PROCEDURE on_ins_emp();

        CREATE TRIGGER on_insert AFTER INSERT on payroll
            FOR EACH ROW EXECUTE PROCEDURE on_ins_payroll();

    The name of the trigger  is  the  same  but  the  table  they
    triggered  for  differs  and they call different functions. I
    don't want to loose this so we cannot use  the  name  of  the
    trigger  (on_insert)  to  create  the  trigger function since
    overloading depends on different  call  arguments.  But  both
    functions have no call arguments.

    Clear now?

>
> Vadim
> P.S. Sorry, I'm very busy currently :((
>
>


Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#======================================== jwieck@debis.com (Jan Wieck) #

pgsql-hackers by date:

Previous
From: The Hermit Hacker
Date:
Subject: Re: [HACKERS] HELP all women were raped during the May riots in Jakarta
Next
From: Andreas Zeugswetter
Date:
Subject: Re: [HACKERS] Rule system (trigger names)