We use JSONB to store elements occasionally. This gets passed to Redshift as a string, that I then parse using a UDF. For an audit report, I want to present one part of the JSON in one column, and a different part in the other. Rather than call two UDFs in every row, can I call one UDF that returns two values?
As a toy example consider a transactional database where for every row we store the method a customer used to pay. Some customers can pay with multiple amounts (eg spend down a gift card and then cover the difference in cash), and thus we store a JSON blob in this field.
{"Methods": [
{"Type":"Gift Card", "Amount": 5.74}
,{"Type":"Cash", "Amount": 4.26}
],
"Coupons": [
{"Code": "XHAY12", "Amount":1.22},
{"Code": "Y123A", "Amount": 4.66}
]}
In my report, I want a column (methods) that shows the cash amount and a second column coupons > $5) that shows whether the transaction got more than $5 off.
I've tried RETURNS float, int as well with brackets, braces and parentheses but get generic syntax errors. Anyone have a suggestion? Or do I need to suck it up and have separate functions?