Is there a method to Execute update in Pl/Pgsql function using rowtype variable - Mailing list pgsql-general

From Tomasz Olszak
Subject Is there a method to Execute update in Pl/Pgsql function using rowtype variable
Date
Msg-id 46c0e33.55d96a15.49c3512a.a58ac@o2.pl
Whole thread Raw
List 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




pgsql-general by date:

Previous
From: "Albe Laurenz"
Date:
Subject: Re: Special charaters
Next
From: Peter Eisentraut
Date:
Subject: Re: Multiple natural joins