I worked out how to do it using unnest(...) with ordinality and returning an array as part of the results.
Here is the function definition:
create function summarize_tables(categories text, variadic tbls name)
returns table (tbl name, overall text, by_category text)
foreach tbl in array tbls
I have had to deal with the problem with a table that can grow and shrink the number of columns.
I did the same thing you did and that is dynamically construct the SQL to create the new table. the problem becomes how to return the table in a simple query from a function. Flat out one can not do that. so the Solution is very simple pass ...
You described the problem well. I cannot give a complete solution, but I'll give you a few ideas.
As you have found out, a function where the number of result columns is variable cannot be done the way you want; if you define it as RETURNS SETOF record, you'll have to specify the actual result columns in every query to the function. This is because the ...
Aggregation sorts the documents based on the inputs INPUT_EXPRESSION and SORT_ORDER. The input expression is matched with the customFieldArray's custom_field_id value and the documents are sorted based on the corresponding field_value.
var INPUT_EXPRESSION = "fname"; // values can be "fname", "city" or "lname"
var SORT_ORDER = 1; // values can be 1 (...