Question about accessing current row data inside trigger

Started by peter Willisabout 21 years ago5 messagesgeneral
Jump to latest
#1peter Willis
peterw@borstad.com

Hello,

I have a trigger function written in C.
The trigger function is called via:

CREATE TRIGGER after_update AFTER UPDATE ON some_table
FOR EACH ROW EXECUTE PROCEDURE my_trigger_function();

Since the trigger is called after each row update the actual row data
should be available in some way to the trigger.
What functionality (SPI ?) do I use to use the column values from
the current row in the actual trigger?

thanks for any insight,

Peter

#2Michael Fuhr
mike@fuhr.org
In reply to: peter Willis (#1)
Re: Question about accessing current row data inside trigger

On Tue, Mar 08, 2005 at 11:37:14AM -0800, peter Willis wrote:

I have a trigger function written in C.
The trigger function is called via:

CREATE TRIGGER after_update AFTER UPDATE ON some_table
FOR EACH ROW EXECUTE PROCEDURE my_trigger_function();

Since the trigger is called after each row update the actual row data
should be available in some way to the trigger.
What functionality (SPI ?) do I use to use the column values from
the current row in the actual trigger?

See "Writing Trigger Functions in C" and "C-Language Functions" in
the documentation. Here are links to documentation for the latest
version of PostgreSQL:

http://www.postgresql.org/docs/8.0/interactive/trigger-interface.html
http://www.postgresql.org/docs/8.0/interactive/xfunc-c.html

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: peter Willis (#1)
Re: Question about accessing current row data inside trigger

peter Willis <peterw@borstad.com> writes:

I have a trigger function written in C.
...
Since the trigger is called after each row update the actual row data
should be available in some way to the trigger.

Sure: tg_trigtuple or tg_newtuple depending on which state you want.
See
http://www.postgresql.org/docs/8.0/static/trigger-interface.html

regards, tom lane

#4peter Willis
peterw@borstad.com
In reply to: Michael Fuhr (#2)
Re: Question about accessing current row data inside trigger

Hello,

I resolved this issue already.
The trigger now works fine.
I was looking at the wrong structure.

Thanks,

Peter

Michael Fuhr wrote:

Show quoted text

On Tue, Mar 08, 2005 at 11:37:14AM -0800, peter Willis wrote:

I have a trigger function written in C.
The trigger function is called via:

CREATE TRIGGER after_update AFTER UPDATE ON some_table
FOR EACH ROW EXECUTE PROCEDURE my_trigger_function();

Since the trigger is called after each row update the actual row data
should be available in some way to the trigger.
What functionality (SPI ?) do I use to use the column values from
the current row in the actual trigger?

See "Writing Trigger Functions in C" and "C-Language Functions" in
the documentation. Here are links to documentation for the latest
version of PostgreSQL:

http://www.postgresql.org/docs/8.0/interactive/trigger-interface.html
http://www.postgresql.org/docs/8.0/interactive/xfunc-c.html

#5peter Willis
peterw@borstad.com
In reply to: Tom Lane (#3)
Re: Question about accessing current row data inside trigger

Hello,

This issue is resolved.
I was using the wrong struct.

Peter

Tom Lane wrote:

Show quoted text

peter Willis <peterw@borstad.com> writes:

I have a trigger function written in C.
...
Since the trigger is called after each row update the actual row data
should be available in some way to the trigger.

Sure: tg_trigtuple or tg_newtuple depending on which state you want.
See
http://www.postgresql.org/docs/8.0/static/trigger-interface.html

regards, tom lane