Re: SELECT DISTINCT ON removes results
От
David G. Johnston
Тема
Re: SELECT DISTINCT ON removes results
Дата
Msg-id
CAKFQuwZP0nFa1BuaZYD64V3kvXJET_7D6kwtJmdW8QR-p5uuxg@mail.gmail.com
Ответ на
SELECT DISTINCT ON removes results (Guyren Howe)
Список
Дерево обсуждения
SELECT DISTINCT ON removes results Guyren Howe <guyren@gmail.com>
Re: SELECT DISTINCT ON removes results Geoff Winkless <pgsqladmin@geoff.dj>
Re: SELECT DISTINCT ON removes results "David G. Johnston" <david.g.johnston@gmail.com>
Re: SELECT DISTINCT ON removes results Guyren Howe <guyren@gmail.com>
Re: SELECT DISTINCT ON removes results Guyren Howe <guyren@gmail.com>
Re: SELECT DISTINCT ON removes results Guyren Howe <guyren@gmail.com>
Re: SELECT DISTINCT ON removes results "David G. Johnston" <david.g.johnston@gmail.com>
Using 9.5, this query:SELECT o.id,
a.number AS awb
FROM pt.orders o
LEFT JOIN (
SELECT DISTINCT ON ((string_agg(air_way_bills.number::text, ','::text)))
string_agg(air_way_bills.number::text, ','::text) AS number,
air_way_bills.order_id
FROM pt.air_way_bills
GROUP BY air_way_bills.order_id) a ON a.order_id = o.idgives me null for awb. Removing the DISTINCT ON clause:
On its face the statement "DISTINCT ON removes results" is not at all surprising given its definition.
Given a self-contained query exhibiting the desired behavior I might be willing to figure out and explain exactly why its happening in that particular circumstance.
Oh, and on its face your DISTINCT ON query doesn't make any sense to me. Using DISTINCT ON on one column but then joining on the discard-able ID column is...unusual.
And it also lacks an ORDER BY for deterministic discarding of duplicate rows.
David J.
В списке pgsql-general по дате отправления