Well, some weeks ago, I read an article about that.
The more efficient approach (in pgplsql) is to use hstore.
With a similar topic, at the end, I created a group of functions that store
in an internal table, data structure for each table under the same generic
trigger.
I also store, primary key.
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
If the connectio
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
On Sun, Aug 13, 2023 at 11:27 AM Rhys A.D. Stewart
wrote:
>
> Hey Adrian,
>
> Thanks for your response. I don't think I explained myself clearly.
> pk_col is not the column name. pk_col is a variable that holds the
> name of a column. This is one trigger for several tables with varying
> structure
On Sat, Aug 12, 2023 at 1:10 PM Rhys A.D. Stewart
wrote:
> Am I missing out on a simpler or more elegant solution?
>
>
No, you are not (at least among SQL and pl/pgsql. SQL is strongly and
statically typed. Circumventing that has a cost, but at least you do have
tools at hand when you find the
On 8/12/23 20:21, Rhys A.D. Stewart wrote:
Hey Adrian,
Thanks for your response. I don't think I explained myself clearly.
pk_col is not the column name. pk_col is a variable that holds the
name of a column. This is one trigger for several tables with varying
structures. So pk_col would be a col
Hey Adrian,
Thanks for your response. I don't think I explained myself clearly.
pk_col is not the column name. pk_col is a variable that holds the
name of a column. This is one trigger for several tables with varying
structures. So pk_col would be a column specific to the current
TG_TABLE_NAME whe
On 8/12/23 13:09, Rhys A.D. Stewart wrote:
Greetings all,
I am writing a trigger and would like to know how to dynamically
access a column from the "OLD" variable. pk_col is the column name
from the table.
I've come up with either doing this:
EXECUTE format('SELECT $1.%1$I', pk_col) INTO pk_val
On 8/12/23 13:09, Rhys A.D. Stewart wrote:
Greetings all,
I am writing a trigger and would like to know how to dynamically
access a column from the "OLD" variable. pk_col is the column name
from the table.
I've come up with either doing this:
EXECUTE format('SELECT $1.%1$I', pk_col) INTO pk_val
Greetings all,
I am writing a trigger and would like to know how to dynamically
access a column from the "OLD" variable. pk_col is the column name
from the table.
I've come up with either doing this:
EXECUTE format('SELECT $1.%1$I', pk_col) INTO pk_val USING OLD;
which looks a bit excessive, or
10 matches
Mail list logo