Re: Dynamically update NEW columns in plpgsql trigger

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Nick <nboutelier(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Dynamically update NEW columns in plpgsql trigger
Date: 2010-09-09 06:06:37
Message-ID: AANLkTikOmX0pZm-zBZNCjcFR5cCy+SP44k=NopqN_Xh5@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello

plpgsql isn't good tool for this. use a plperl or plpython instead.
your solution is extremly slow.

Regards

Pavel Stehule

2010/9/9 Nick <nboutelier(at)gmail(dot)com>:
> I need to dynamically update NEW columns. Ive been inserting the NEW
> values into a temp table, updating them, then passing the temp table
> values back to NEW (is there a better way?). Ive had success with this
> method unless there is a null value...
>
> EXECUTE 'CREATE TEMP TABLE new AS SELECT $1.*' USING NEW;
> EXECUTE 'UPDATE new SET ' || dyn_col_name || ' = 1';
> EXECUTE 'SELECT * FROM new' INTO NEW;
> EXECUTE 'DROP TABLE new';
>
> This last line...
> EXECUTE 'SELECT $1.' || dyn_col_name INTO val USING NEW;
>
> gives the ERROR: could not identify column "col_one" in record data
> type.
>
> However RAISE EXCEPTION '%',NEW.col_one;
> returns "1" correctly.
>
> If col_one does does not start out as a null value, then everything
> works. Why does the passing from temp table back to NEW lose the USING
> functionality?
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dmitriy Igrishin 2010-09-09 09:21:43 Re: Dynamically update NEW columns in plpgsql trigger
Previous Message John R Pierce 2010-09-09 05:18:00 Re: line CASE statemelnt in query a la Oracle