From: | Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk> |
---|---|
To: | Ondřej Bouda <obouda(at)email(dot)cz> |
Cc: | Rob Nikander <rob(dot)nikander(at)gmail(dot)com>, Postgres General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: query patterns for multipass aggregating |
Date: | 2018-11-11 19:20:58 |
Message-ID: | 871s7rwhfk.fsf@news-spur.riddles.org.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
>>>>> "Ondřej" == Ondřej Bouda <obouda(at)email(dot)cz> writes:
Ondřej> What about subqueries?
Ondřej> SELECT
Ondřej> items.*,
Ondřej> (SELECT array_agg(color_name) FROM colors WHERE item_id =
Ondřej> items.id) AS color_names,
Ondřej> (SELECT array_agg(image_file) FROM images WHERE item_id =
Ondřej> items.id) AS image_files
Ondřej> FROM items
Ondřej> According to my experience, not only the code is readable (no
Ondřej> questions about how many rows are there for each item), but it
Ondřej> also leads to a better query plan.
This is (generally speaking) no improvement over the LATERAL method I
showed, and is less flexible (for example it's very painful to return
more than one value from the subqueries).
--
Andrew (irc:RhodiumToad)
From | Date | Subject | |
---|---|---|---|
Next Message | Rich Shepard | 2018-11-11 19:21:25 | Move cluster to new host, upgraded version |
Previous Message | Florian Bachmann | 2018-11-11 19:10:35 | Re: Copy data from DB2 (Linux) to PG |