|
|
|
|
|
by gavinray
871 days ago
|
|
They're incredibly useful -- any time that you want to both: - Reference data from the previous part of the query (the "left-hand side") - Return multiple columns The only way you can achieve it is with LATERAL/CROSS APPLY. Regular correlated subqueries can only return a single column, so something like this doesn't work: SELECT
loop.val, (SELECT loop.val * loop.val, 'second column') AS squared
FROM
(SELECT loop.val FROM generate_series(1,5) AS loop(val)) as loop
You'd get: error: subquery must return only one column
|
|
It's sets all the way down. A set of f(x) is still a set.