Does SQL have the concept of a function that returns multiple columns, outside of a table function? Here would be an example:
SELECT
id,
SPLIT_NAME(name, ' ')
FROM
table
And I want the SPLIT_NAME
function to produce two columns, one for first and one for last, so the output would be:
id first last
1 tom jones
I know this can be done with:
SELECT id, SPLIT(...) first, SPLIT(...) last FROM table
Or possibly with a table function such as:
SELECT id, first, last FROM table, SPLIT_NAME(name, ' ')
But, wondering if SQL has any sort of scalar-ish function that can produce multiple outputs, as I think a join
could be quite expensive (I think?) if joining to something like a billion rows where (hopefully) the function itself could just be inlined.
Note: either Postgres or SQL Server is fine.