Re: set difference

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: set difference
Дата
Msg-id 14808.1034691939@sss.pgh.pa.us
обсуждение исходный текст
Ответ на set difference  (Domoszlai László <dlacko@finit.hu>)
Список pgsql-sql
Domoszlai László <dlacko@finit.hu> writes:
> I would like to make symmetrical(set) difference in a query.
> But the simpliest way I could find is 

> select id from a 
> except
> select id from b
> union 
> select id from b
> except
> select id from a

> Is there any better solution for this problem?

One thing you should definitely do is change "union" to "union all".
"union" implies a pass of duplicate removal, which shouldn't be
necessary here (unless a or b individually contain duplicates and
you want to get rid of those too).

Another thing to try is(a union b) except (a intersect b)
(Again, you might be able to say union all instead of union.)
Not sure which will be faster.
        regards, tom lane


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

Предыдущее
От: Jeff
Дата:
Сообщение: Re: how do i insert an empty string ?
Следующее
От: "Josh Berkus"
Дата:
Сообщение: Re: Messy Casts, Is there a better way?