Description
Implement a built-in function working the opposite way to the existing aggregate function LIST
- i.e. parse the delimited string and return a record set containing the parsed values.
It may be a possible solution for #3821, as it would be possible to do WHERE ID IN (SELECT * FROM UNLIST(...))
The name UNLIST
is suggested due to (1) being an antipode to the existing LIST
function (even if we add a standard synonym LISTAGG
one day) and (2) SQL standard having the UNNEST
table-value function which does the similar job just for arrays/multi-sets.
Syntax:
<list derived table> ::= UNLIST(<value> [, <separator>] [<data type conversion>])
<separator> ::= <value>
<data type conversion> ::= RETURNING <data type>
If <separator>
is omitted, comma is implied (as for LIST
). If <data type conversion>
is omitted, resulting field has the data type of the first input parameter.
The RETURNING syntax look weird, but this is exactly how SQL specification declares the output data type in JSON functions, so we used the same approach here.
Remaining questions:
- I suppose it's OK to imply
UNLIST
as relation name if theAS
clause is omitted. But I'm not sure about the column name - should we also implyUNLIST
, or maybe use keywordVALUE
or maybe some other ideas?
select unlist from unlist(...)
select value from unlist(...)
select unlist.unlist from unlist(...)
select unlist.value from unlist(...)
-
Should we trim the parsed strings under the hood, or make it optional, or leave it up to developers?
select * from unlist('1, 2, 3')
-
If
<data type conversion>
is omitted and the input argument is BLOB, should we return also BLOB or maybe VARCHAR(MAX)?