From: Josh Berkus <josh@agliodbs.com>
To: Larry Rosenman <ler@lerctr.org>
Cc: pgsql-sql@postgresql.org
Subject: Re: trigger question
Date: Thu, 16 May 2002 11:05:48 -0700
Message-ID: <200205161105.48972.josh@agliodbs.com> (raw)
In-Reply-To: <1021571463.95676.11.camel@ler-freebie.iadfw.net>
References: <1021570694.95676.7.camel@ler-freebie.iadfw.net>
<200205161049.23148.josh@agliodbs.com>
<1021571463.95676.11.camel@ler-freebie.iadfw.net>
Larry,
> I want to log the changes to it in a trigger. Occasionally we add fields to
it, so
> I'd like the trigger to know about them automatically. I need to log
old/new for just the fields
> that change (and the netblock, which is the primary key).
The problem is, there is no way for you to loop through all of the fields in a
RECORD without knowing in advance what those fields are. There is no
NEW.field(1) that I know of. And RECORD data types are not accessable in
dynamic EXECUTE strings.
So, two approaches:
1. do all this in C and manipulate the Postgres data libraries directly,
allowing you to loop through the collection of fields in a table. Don't ask
me how to do this; you'll have to take it up on PGSQL-HACKERS.
2. Save the entire old record (BEFORE update), and then the entire new record
(AFTER update) to a history buffer table. Use the pgsql system tables to
loop through the fields in the main table, logging each entry where the two
fields are different.
The two problems with approach #2 are: 1. you cannot reject updates this way,
and 2. it'll be dog slow.
The simpler solution is for you do decide on a permanent structure for your
table, neh?
--
-Josh Berkus
______AGLIO DATABASE SOLUTIONS___________________________
Josh Berkus
Complete information technology josh@agliodbs.com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: josh@agliodbs.com, ler@lerctr.org
Subject: Re: trigger question
In-Reply-To: <200205161105.48972.josh@agliodbs.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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