pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedtriggers and plpgsql question
4+ messages / 2 participants
[nested] [flat]
* triggers and plpgsql question
@ 2002-08-27 16:18 Mathieu Arnold <mat@mat.cc>
0 siblings, 1 reply; 4+ messages in thread
From: Mathieu Arnold @ 2002-08-27 16:18 UTC (permalink / raw)
To: pgsql-sql
Hi
I want to do a generic function that I can add to triggers to add every
inserts, updates and deletes from many differents tables into a common
format in another table. the idea is :
create function do_it_all () returns opaque '
begin
IF TG_OP = ''INSERT'' THEN
cycle through all of NEW (not knowing what it contains) and do things
with them
ELSIF TG_OP = ''UPDATE'' THEN
cycle through all of NEW (not knowing what it contains) and do things
with them
ELSIF TG_OP = ''DELETE'' THEN
say that NEW.id_||TG_RELNAME has been deleted
END IF;
END;
The thing I need, is to be able to know what does NEW contains, and I have
not found out any mean to do so. If it's not possible to do so, I'll write
a function per table, but for the beauty of all this, I would have liked to
do it the way above.
--
Mathieu Arnold
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: triggers and plpgsql question
@ 2002-08-27 22:38 Josh Berkus <josh@agliodbs.com>
parent: Mathieu Arnold <mat@mat.cc>
0 siblings, 1 reply; 4+ messages in thread
From: Josh Berkus @ 2002-08-27 22:38 UTC (permalink / raw)
To: Mathieu Arnold <mat@mat.cc>; pgsql-sql
Mathieu,
> The thing I need, is to be able to know what does NEW contains, and I have
> not found out any mean to do so. If it's not possible to do so, I'll write
> a function per table, but for the beauty of all this, I would have liked to
> do it the way above.
You can't do this in PL/pgSQL. See the online documentation on writing
triggers in C; that is the only way to get what you want.
--
-Josh Berkus
Aglio Database Solutions
San Francisco
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: triggers and plpgsql question
@ 2002-08-28 06:42 Mathieu Arnold <mat@mat.cc>
parent: Josh Berkus <josh@agliodbs.com>
0 siblings, 1 reply; 4+ messages in thread
From: Mathieu Arnold @ 2002-08-28 06:42 UTC (permalink / raw)
To: josh@agliodbs.com; +Cc: pgsql-sql
--On mardi 27 août 2002 15:38 -0700 Josh Berkus <josh@agliodbs.com> wrote:
>
> Mathieu,
>
>> The thing I need, is to be able to know what does NEW contains, and I
>> have not found out any mean to do so. If it's not possible to do so,
>> I'll write a function per table, but for the beauty of all this, I would
>> have liked to do it the way above.
>
> You can't do this in PL/pgSQL. See the online documentation on writing
> triggers in C; that is the only way to get what you want.
So, if I want to avoid C, I'll have to write a function per table. I'll
have a look at SPI (as I believe after a short readout of the doc, I'll
need it).
--
Mathieu Arnold
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: triggers and plpgsql question
@ 2002-08-28 14:22 Mathieu Arnold <mat@mat.cc>
parent: Mathieu Arnold <mat@mat.cc>
0 siblings, 0 replies; 4+ messages in thread
From: Mathieu Arnold @ 2002-08-28 14:22 UTC (permalink / raw)
To: josh@agliodbs.com; +Cc: pgsql-sql
--On mercredi 28 août 2002 08:42 +0200 Mathieu Arnold <mat@mat.cc> wrote:
>
>
> --On mardi 27 août 2002 15:38 -0700 Josh Berkus <josh@agliodbs.com> wrote:
>
>>
>> Mathieu,
>>
>>> The thing I need, is to be able to know what does NEW contains, and I
>>> have not found out any mean to do so. If it's not possible to do so,
>>> I'll write a function per table, but for the beauty of all this, I would
>>> have liked to do it the way above.
>>
>> You can't do this in PL/pgSQL. See the online documentation on writing
>> triggers in C; that is the only way to get what you want.
>
> So, if I want to avoid C, I'll have to write a function per table. I'll
> have a look at SPI (as I believe after a short readout of the doc, I'll
> need it).
After a few hours of work, here is what I did. What it does is to log
everything that gets inserted, deleted or updated into a table. I post it
here because I believe that someone else might be interested.
--
Mathieu Arnold
Attachments:
triggers.c (application/octet-stream, 4.2K) download
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2002-08-28 14:22 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-08-27 16:18 triggers and plpgsql question Mathieu Arnold <mat@mat.cc>
2002-08-27 22:38 ` Josh Berkus <josh@agliodbs.com>
2002-08-28 06:42 ` Mathieu Arnold <mat@mat.cc>
2002-08-28 14:22 ` Mathieu Arnold <mat@mat.cc>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox