Re: Dynamically accessing columns from a row type in a trigger - Mailing list pgsql-general

From Rhys A.D. Stewart
Subject Re: Dynamically accessing columns from a row type in a trigger
Date
Msg-id CACg0vT=ELyfN5NEdp001TkJQxKyoxAAyUPwMmY_d+xYBHYMRtg@mail.gmail.com
Whole thread Raw
In response to Re: Dynamically accessing columns from a row type in a trigger  (jian he <jian.universality@gmail.com>)
Responses Re: Dynamically accessing columns from a row type in a trigger  (Rob Sargent <robjsargent@gmail.com>)
List pgsql-general
Hello again



> > Actually, now that I'm thinking about it, I don't really want to store
> > the value into a variable because the pk_col might be of any given
> > type. So ideally, I'd love a way to just get the value from OLD and
> > use it directly in another query. Something along the lines of:
> >
> > `EXECUTE format('SELECT * FROM %1$I.sometable WHERE pk = $1', myschma)
> > USING OLD['pk_col']`.
> >
> > I reckon I may have to look at just generating a trigger function per
> > table, or maybe look into using TG_ARGS.



So the less obvious solution that works is to create a temporary
table. A little verbose, but I get to keep the types.

`CREATE TEMPORARY TABLE _ ON COMMIT DROP AS SELECT OLD.*;`

_ as a table name makes things a little easier to type.



Rhys
Peace & Love | Live Long & Prosper



pgsql-general by date:

Previous
From: Ron
Date:
Subject: Re: Fatal Error : Invalid Memory alloc request size 1236252631
Next
From: Rob Sargent
Date:
Subject: Re: Dynamically accessing columns from a row type in a trigger