I have multiple functions that all return the same data structure in a table. I have 1 function that calls all of them via a UNION and it returns the results in a table format. How do I get that 1 function to return the results from all the subfunctions in a json?
I tried doing:
SELECT row_to_json(t) from (select col1, col2, col3 from db.subfunction1())
UNION
SELECT row_to_json(t) from (select col1, col2, col3 from db.subfunction2())
UNION
SELECT row_to_json(t) from (select col1, col2, col3 from db.subfunction3());
and got
ERROR: Could not identify an equality operator for type json LINE 1: select row_to_json(t) from (select.......... ^ SQL state: 42883 Character: 8
OKay, so I run the following: Select * from db.subfunction1();
The result is a table
| data type | A date | some text | Another text field |
|---|---|---|---|
| Something | 2021-01-31 | detail info | ip4: 5663773; |
Each function does the same thing. I want the parent function to convert the output to JSON.
(than)is this correct ? Please, can you share expected results, and the definition of the functionsdb.subfunction1(),db.subfunction2()anddb.subfunction3()select col1, col2, col3 from db.subfunction1()UNION ALLinstead ofUNIONwhich won't need an equality operator. Unless you actually need to filter for duplicates?