I am reading the documentation and trying to get to the bottom of some queries.
Here is a query with both t
and u
SELECT * FROM (VALUES 1, 2) t("left"), (VALUES 3, 4) u("right");
Here is another using only t
:
SELECT * FROM (VALUES 5, 2, 4, 1, 3) t(x) ORDER BY x OFFSET 2 LIMIT 2;
There are also these two (notice the space between the t
and the (
):
SELECT student, score
FROM tests
CROSS JOIN UNNEST(scores) AS t (score);
FROM (
VALUES
(ARRAY[2, 5], ARRAY['dog', 'cat', 'bird']),
(ARRAY[7, 8, 9], ARRAY['cow', 'pig'])
) AS x (numbers, animals)
CROSS JOIN UNNEST(numbers, animals) AS t (n, a);
Here t(sites)
is described as an alias.
FROM dataset, UNNEST(items) AS t(sites)
I have googled for hours. I hope someone with more SQL experience can point me toward useful search strings.
- Are both u and t predefined aliases?
- What do the aliases mean
- Do I need the parentheses for the alias to work?
- Do the space between the character and the parentheses have any special meaning?