Store or log actual dynamic SQL EXECUTE ... format() ... USING

by Alan Whited   Last Updated October 19, 2018 21:06 PM

exec_str := format( ' UPDATE schema.table SET some_code = ''P'' , that_id = $1
WHERE attribute_id = $2 AND somejsonb#>>''{' || '%I' || '}'' like $3 AND that_id is null AND attribute_id = 214158 ', _element ) ; insert into schema.script_log (caller,script_text) VALUES (current_query(),exec_str);

-- execute dsql
EXECUTE exec_str USING _that_id, in_attribute_id, _pattern;
`

How can I either log the actual statement executed, or retrieve the last statement executed afterwards. Currently it only logs with $1, $2, $3. I don't want logging turned on for everything, I just want it in certain transactions/functions with dynamic SQL to the log table.

Postgres 9.6



Related Questions


Postgres gist slow index f_unaccent

Updated April 09, 2018 20:06 PM