Iterating over rowtype/record fields?

From: Bill Gribble <grib(at)linuxdevel(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Iterating over rowtype/record fields?
Date: 2002-05-16 13:14:55
Message-ID: 1021554896.11133.12.camel@flophouse
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I've looked online and in the 7.1 docs but I can't locate much
information about the RECORD type and what I can do with it from
pl/pgsql. Are there any introspection or iteration functions that would
allow me to look at all the columns in a record without explicitly
writing RECORD.column?

I'm trying to write a fairly generic pl/pgsql trigger function to log
changes to a specified set of tables into another table. So I can
easily get a NEW and OLD record, but in the generic case I don't know
what type of table they represent. I'd like to just say something like

FOR f IN table%ROWTYPE LOOP
IF OLD.f != NEW.f THEN
make_log_entry(table, NEW.rownum, f, NEW.f);
END IF
END LOOP

don't think that works tho :)

Any ideas how I can do something like the above?

Thanks,
Bill Gribble

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2002-05-16 13:52:17 Re: Iterating over rowtype/record fields?
Previous Message Peter Gibbs 2002-05-16 12:57:40 Re: Lexicographic index ?