Dynamic Assignment

From: "Andy Chambers" <achambers(at)mcna(dot)net>
To: "Postgresql (General)" <pgsql-general(at)postgresql(dot)org>
Subject: Dynamic Assignment
Date: 2011-03-23 16:43:44
Message-ID: op.vss12610cqhz04@vaio.mcnaitdept
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi All,

In a trigger function, I'm trying to set the variable "pkey" to be one of
the columns
in the automatic variable "NEW". Which one depends on some metadata that
is available at
run-time. I'm having a hard time using an automatic variable in a dynamic
execute command.

I get the error "missing FROM-clause entry for table "new""

Here's my function

create or replace function refresh_row () returns trigger as $$

declare
pkey bigint;
begin
execute 'select NEW.esid' into pkey;
end;
$$ language plpgsql

Obviously this particular code could be re-written as a simple assignment
but I need the
"esid" part to be dynamic. Is this possible?

Cheers,
Andy

--
Andy Chambers

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Yandong.Yao 2011-03-23 16:44:16 What does error "psql: Kerberos 5 authentication not supported" means?
Previous Message Tom Lane 2011-03-23 16:42:42 Re: Recursive function that receives a list of IDs and returns all child IDs