Обсуждение: triggers and TriggerData

Поиск
Список
Период
Сортировка

triggers and TriggerData

От
gustavo halperin
Дата:
First, thank you for your answers about my problem with the function
'CREATE TRIGGER',
I have another question about triggers, how can I pass arguments ?? I
read about some struct TriggerData *CurrentTriggerData, but I didn't
found any explanation or example about how to use it in postgres SQL.
 My problem is that  for any INSERT row in table 'B' I need to pass to
the function trigger two values  of this row.  Do you know how to do so
or where are examples of how to do it ??


  Thank you again,
          Gustavo

--
                           ||\             // \
                           | \\           //   |
I'm thinking.               \  \\  l\\l_ //    |
    _              _         |  \\/ `/  `.|    |
  /~\\   \        //~\       | Y |   |   ||  Y |
  |  \\   \      //  |       |  \|   |   |\ /  |
  [   ||        ||   ]       \   |  o|o  | >  /
 ] Y  ||        ||  Y [       \___\_--_ /_/__/
 |  \_|l,------.l|_/  |       /.-\(____) /--.\
 |   >'          `<   |       `--(______)----'
 \  (/~`--____--'~\)  /           U// U / \
  `-_>-__________-<_-'            / \  / /|
      /(_#(__)#_)\               ( .) / / ]
      \___/__\___/                `.`' /   [
       /__`--'__\                  |`-'    |
    /\(__,>-~~ __)                 |       |__
 /\//\\(  `--~~ )                 _l       |--:.
 '\/  <^\      /^>               |  `   (  <   \\
      _\ >-__-< /_             ,-\  ,-~~->. \   `:.___,/
     (___\    /___)           (____/    (____)    `---'


Re: triggers and TriggerData

От
Alan Hodgson
Дата:
On Sunday 21 January 2007 15:56, gustavo halperin
<ggh.develop@gmail.com> wrote:
> First, thank you for your answers about my problem with the function
> 'CREATE TRIGGER',
> I have another question about triggers, how can I pass arguments ?? I
> read about some struct TriggerData *CurrentTriggerData, but I didn't
> found any explanation or example about how to use it in postgres SQL.
>  My problem is that  for any INSERT row in table 'B' I need to pass
> to the function trigger two values  of this row.  Do you know how to
> do so or where are examples of how to do it ??

You cannot pass values to a trigger.

However, insert triggers (in PLpgSQL at least) receive the row value in
the NEW record variable.  There are examples in the documentation.

http://www.postgresql.org/docs/8.2/interactive/plpgsql-trigger.html#PLPGSQL-TRIGGER-EXAMPLE

--
"A government that robs Peter to pay Paul can always depend upon the
support of Paul." - George Bernard Shaw


Re: triggers and TriggerData

От
Michael Fuhr
Дата:
On Sun, Jan 21, 2007 at 09:05:30PM -0800, Alan Hodgson wrote:
> On Sunday 21 January 2007 15:56, gustavo halperin <ggh.develop@gmail.com> wrote:
> > I have another question about triggers, how can I pass arguments ?? I
> > read about some struct TriggerData *CurrentTriggerData, but I didn't
> > found any explanation or example about how to use it in postgres SQL.
> > My problem is that  for any INSERT row in table 'B' I need to pass
> > to the function trigger two values  of this row.  Do you know how to
> > do so or where are examples of how to do it ??
>
> You cannot pass values to a trigger.

You can pass literal string arguments to a trigger function.  See
the CREATE TRIGGER documentation and, for PL/pgSQL, TG_ARGV and
TG_NARGS.  For C see "Writing Trigger Functions in C"; search for
tgnargs and tgargs.

http://www.postgresql.org/docs/8.2/interactive/sql-createtrigger.html
http://www.postgresql.org/docs/8.2/interactive/plpgsql-trigger.html
http://www.postgresql.org/docs/8.2/interactive/trigger-interface.html

(These links are to the 8.2 documentation but earlier versions also
support arguments to trigger functions.)

--
Michael Fuhr

Re: triggers and TriggerData

От
Alan Hodgson
Дата:
On Monday 22 January 2007 07:04, Michael Fuhr <mike@fuhr.org> wrote:
> You can pass literal string arguments to a trigger function.  See
> the CREATE TRIGGER documentation and, for PL/pgSQL, TG_ARGV and
> TG_NARGS.  For C see "Writing Trigger Functions in C"; search for
> tgnargs and tgargs.
>
> http://www.postgresql.org/docs/8.2/interactive/sql-createtrigger.html
> http://www.postgresql.org/docs/8.2/interactive/plpgsql-trigger.html
> http://www.postgresql.org/docs/8.2/interactive/trigger-interface.html
>
> (These links are to the 8.2 documentation but earlier versions also
> support arguments to trigger functions.)

I stand corrected.  And I can imagine some uses for passing string constants
to triggers, but nothing related to what the OP was looking for ...

--
99 percent of lawyers give the rest a bad name