Re: filter duplicates by priority

Поиск
Список
Период
Сортировка
От Clark Slater
Тема Re: filter duplicates by priority
Дата
Msg-id 51354.96.236.139.176.1247671570.squirrel@webmail10.pair.com
обсуждение исходный текст
Ответ на Re: filter duplicates by priority  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
This solved my problem.  Now why didn't I think of that!?  Thank you very
much everybody.  This list is an incredible resource.

-Clark


> AFAICS, changing it to ORDER BY part_number,priority would solve the
> stated problem.  If you really need the final result in priority rather
> than part number order, put the whole thing in a sub-select and re-sort
> outside it.
>
>             regards, tom lane
>
> "Clark Slater" <pg@slatech.com> writes:
>> I am trying to use DISTINCT ON to filter out *potential* duplicate
>> values
>> from a set of sub queries.  There are certain cases where there can be
>> repetitive part numbers that are priced differently.  I'm trying to
>> start
>> with the full list, ordered by priority, and then remove any repeats
>> that
>> have a lesser priority.
>
>> SELECT DISTINCT ON (part_number) * FROM (
>> SELECT part_number, priority FROM ...
>> UNION ALL
>> SELECT part_number, priority FROM ...
>> UNION ALL
>> SELECT part_number, priority FROM ...
>> ) AS filter_duplicates ORDER BY priority,part_number
>
>> The above statement does not work because if I ORDER BY
>> priority,part_number then I have to DISTINCT ON (priority,part_number).
>> But DISTINCT ON (priority, part_number) does not remove the repeated
>> rows
>> because the same part_number with a different priority becomes a
>> distinct
>> tuple.


В списке pgsql-general по дате отправления:

Предыдущее
От: "Abraham, Danny"
Дата:
Сообщение: initdb --locale=LATIN1 fails on Windows
Следующее
От: Stuart Bishop
Дата:
Сообщение: Connection pool or load balancer supporting ident authentication