Dynamic binding issue

From: Lorusso Domenico <domenico(dot)l76(at)gmail(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Dynamic binding issue
Date: 2023-06-12 22:13:43
Message-ID: CAJMpnG6sN3KWMq4KZ21eMUZWvGSpkYZ7S_XdBtLdb4_nFdksQQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello guys,
I'm a problem with dynamic sql.
I am trying to write a generic function that is able to read and update a
table based on some data coming from e previous record.
Here the example
_sqlStr=format('select *
from %1$s.%2$s
where (' || array_to_string(_activeRec.pk_columns_list, ',') || ') in
(select ' ||
'row($1[''' || array_to_string(_activeRec.pk_columns_list, '''],$1[''')
|| ''']))'
, _activeRec.name_of_schema, _activeRec.main_table);

execute _sqlStr using oldRec into _rec;

My problem is oldRec is a type record, so the substitution performed by
execute fails, because it can't recognize the field if the variable is
record and not a specific composite record type.

I suppose this is a recurrent question, but I can't find a solution...

--
Domenico L.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2023-06-12 23:31:44 Re: Dynamic binding issue
Previous Message Raj Kiran 2023-06-12 18:57:26 SOC II Type 2 report.