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

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