Is there a method to Execute update in Pl/Pgsql function using rowtype variable

From: Tomasz Olszak <tolszak(at)o2(dot)pl>
To: pgsql-general(at)postgresql(dot)org
Subject: Is there a method to Execute update in Pl/Pgsql function using rowtype variable
Date: 2009-03-20 08:17:46
Message-ID: 46c0e33.55d96a15.49c3512a.a58ac@o2.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Greetings
I have a record variable in plpgsql function:
DECLARE
tabRow  TAB%ROWTYPE;
someVar varchar;
BEGIN
/*I Can do something like this*/
insert into TAB select tabRow.*;
....
/*but i want to update table TAB using variable rowTab*/
/* i know the list of colums that i want to update */
/*I've tried casting Record to text but I can't cast text to record:*/
someVar:=tabRow;
execute 'UPDATE TAB '||upd_expr()||' from CAST ('||someVar||' as TAB) foo where pkey='||tabRow.pkey;
/*
function upd_expr returns string '  col1=x.col2,col2=x.col2, ... , coln=x.coln ';
*/
/*
but "someVar:=tabRow;" makes someVar='(A,B,C,D,,,,,I)' and cast doesn work, it should be someVar='(''A'',''B'',''C'',''D'',NULL,NULL,NULL,NULL,''I'')'
*/
Is there a wa I can do such update?
Regards,
Tomasz

Browse pgsql-general by date

  From Date Subject
Next Message Peter Eisentraut 2009-03-20 08:32:13 Re: Multiple natural joins
Previous Message Albe Laurenz 2009-03-20 07:47:14 Re: Special charaters