Skip to content
Advertisement

How to iterate over a record when the columns are dynamic

I have this function in postgres which takes PVH_COLS_DYNA that contains the columns that are going in to the query:

How can I get the data from the record variable VV_ROW_RECORD, since the columns are dynamic?

Advertisement

Answer

You cannot reference columns like array items, columns have to be referenced by name.

The dynamic part is not getting the row in your example, but referencing each column.

%I is an argument to format(), properly escaping identifiers as needed.
$1 in the query string for EXECUTE is a parameter filled in by the USING clause (not to be confused with function parameters!).

Related answers (with more explanation):

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement