How can I get subquery array and it`s count?
SELECT location.country,
(SELECT array(
SELECT competition.id
FROM competition
WHERE location.id = competition.location_id )) AS list,
array_length(list, 1) AS list_count
FROM location
I am trying to get competition list
for every country
.
Query works fine without: array_length(list, 1) AS list_count
It is arguing that column 'list' doesn't exists
.
Model: http://sqlfiddle.com/#!2/4c449