Give alias / column definition list to ROWS FROM()
-
07-03-2021 - |
Question
This obviously doesn't work:
SELECT regexp_matches[1], regexp_matches[1]
FROM ROWS FROM (
regexp_matches('fooBarBaz', '[[:upper:]]', 'g'),
regexp_matches('fooBarBaz', '[[:lower:]]', 'g')
);
Error: [42702] column reference "regexp_matches" is ambiguous
How can I give an alias to the function calls?
SELECT u[1], l[1]
FROM ROWS FROM (
regexp_matches('fooBarBaz', '[[:upper:]]', 'g'),
regexp_matches('fooBarBaz', '[[:lower:]]', 'g')
) AS (u text[], l text[]);
Error: [42601] ROWS FROM() with multiple functions cannot have a column definition list
Hint: Put a separate column definition list for each function inside ROWS FROM().
SELECT u[1], l[1]
FROM ROWS FROM (
regexp_matches('fooBarBaz', '[[:upper:]]', 'g') AS (u text[]),
regexp_matches('fooBarBaz', '[[:lower:]]', 'g') AS (l text[])
);
Error: [42601] a column definition list is only allowed for functions returning "record"
I'm out of ideas. This has to be possible.
Documentation:
Solution
You need a table alias too
SELECT T.u[1], t.l[1]
FROM ROWS FROM (
regexp_matches('fooBarBaz', '[[:upper:]]', 'g'),
regexp_matches('fooBarBaz', '[[:lower:]]', 'g')
) AS t (u, l);
Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange