Passing arguments to a function called by a trigger

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

Passing arguments to a function called by a trigger

От:
Some Developer <someukdeveloper@gmail.com>
Дата:
I have an INSERT AFTER trigger that runs on inserts into a specific 
table. I'm not sure if the function automatically gets all the 
information that was inserted into the table or whether you have to 
manually pass it in?

If you do have to manually pass it in can someone point me to some 
examples showing the correct syntax to use? I've read through the 
PostgreSQL manual on C functions but most of the trigger examples don't 
take any arguments unfortunately.

Also while I am on the subject can anyone recommend a good book on 
stored procedure programming with PostgreSQL please? I use plpython2u 
and C for my stored procedures if that makes any difference.

Thanks.

Re: Passing arguments to a function called by a trigger

От:
Andreas Kretschmer <akretschmer@spamfence.net>
Дата:
Some Developer  wrote:

> I have an INSERT AFTER trigger that runs on inserts into a specific  
> table. I'm not sure if the function automatically gets all the  
> information that was inserted into the table or whether you have to  
> manually pass it in?

NEW. is your friend ;-)


Andreas
-- 
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."   (unknown)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°

Re: Passing arguments to a function called by a trigger

От:
Some Developer <someukdeveloper@gmail.com>
Дата:
On 27/07/2013 14:05, Andreas Kretschmer wrote:
> Some Developer  wrote:
>
>> I have an INSERT AFTER trigger that runs on inserts into a specific
>> table. I'm not sure if the function automatically gets all the
>> information that was inserted into the table or whether you have to
>> manually pass it in?
>
> NEW. is your friend ;-)
>
>
> Andreas
>

Thanks for the tip. So I can just use NEW. to get the values 
inserted into the table from inside the function that is called by the 
trigger?

Is there a corresponding OLD as well if I ever want to do a trigger on 
an UPDATE?

Re: Passing arguments to a function called by a trigger

От:
amulsul <sul_amul@yahoo.co.in>
Дата:
>Is there a corresponding OLD as well if I ever want to do a trigger on 
an UPDATE? 

Yes, you are correct.

ODL is variable holding the old database row for UPDATE/DELETE operations in
row-level triggers and NEW is holding the new database row.

To get to know more about trigger just follow the tutorial at
http://wiki.postgresql.org/wiki/A_Brief_Real-world_Trigger_Example

I am sure u get more idea about it.

Regards,
Amul Sul



--
View this message in context: http://postgresql.1045698.n5.nabble.com/Passing-arguments-to-a-function-called-by-a-trigger-tp5765350p5765394.html
Sent from the PostgreSQL - novice mailing list archive at Nabble.com.

Re: Passing arguments to a function called by a trigger

От:
Luca Ferrari <fluca1978@infinito.it>
Дата:
On Sat, Jul 27, 2013 at 1:55 PM, Some Developer
 wrote:
> I have an INSERT AFTER trigger that runs on inserts into a specific table.
> I'm not sure if the function automatically gets all the information that was
> inserted into the table or whether you have to manually pass it in?


You have to read the trigger documentation, as already suggested.
Moreover here (https://github.com/fluca1978/fluca1978-pg-utils/blob/master/bsdmag/03-server-side-programming/03-trigger-download_path-improved.sql)
you can find an example of triggers using also parameters passed at
the creation of the trigger (TG_NARGS, TG_ARGV).

Luca

FAQ