Обсуждение: Trigger function, C, lookup of attribute type

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

Trigger function, C, lookup of attribute type

От
Paul
Дата:
I'm writing a trigger procedure in C to catch updates to a
table and write them to a log file.

The function must walk along trigdata->tg_trigtuple
pulling out the attributes, comparing them with those in
trigdata->tg_newtuple and writing the diffs to a flat ASCII
file.

I've got a loop over the attributes, and I can get the values
if I know the type, eg

  Datum d = heap_getattr( trigdata->tg_trigtuple, ...
  int32_t val = DatumGetInt32( d);

but I'm struggling to find how the function can determine the
attribute types.   I'm only using the built-in scalar types.

Do I have to query the system catalogs?  Or maybe there's a
function that works from a TupleDesc?

--
Paul Nicholson
--


Re: Trigger function, C, lookup of attribute type

От
Paul
Дата:
I found the solution: SPI_gettype() does the job fine.

I was led to that by rummaging through the slony source
code to see how they handle the triggers in C.

--
Paul Nicholson
--


Re: Trigger function, C, lookup of attribute type

От
Jim Nasby
Дата:
On 12/15/15 4:42 AM, Paul wrote:
> I'm writing a trigger procedure in C to catch updates to a
> table and write them to a log file.

You might find https://github.com/arkhipov/temporal_tables useful.

Though, if you just want to log things to a file, you should check out
http://pgaudit.org/.
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com