From: Gavin Flower <GavinFlower@archidevsys.co.nz>
To: Vitalii Tymchyshyn <tivv00@gmail.com>
Cc: bricklen <bricklen@gmail.com>
Cc: Merlin Moncure <mmoncure@gmail.com>
Cc: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: array_except -- Find elements that are not common to both arrays
Date: Tue, 04 Oct 2011 20:16:39 +1300
Message-ID: <4E8AB2D7.2010901@archidevsys.co.nz> (raw)
In-Reply-To: <4E85B4AF.2090104@gmail.com>
References: <CAGrpgQ8YkMVpN1scWYbqBW+fdNhSpXFd9T7YqxmGCJKT3XHZnA@mail.gmail.com>
<CAHyXU0wVZ+0A7FCvYNcK_r9UTqutgpjE8MQHXAmb2uv7=0-QZQ@mail.gmail.com>
<CAGrpgQ-Zo6FOtc=NtY-4wXcnYqQRgcRLDR3BGQk2nAXpW46rzA@mail.gmail.com>
<4E85B4AF.2090104@gmail.com>
On 01/10/11 01:23, Vitalii Tymchyshyn wrote:
> Since you are using except and not except all, you are not looking at
> arrays with duplicates.
> For this case next function what the fastest for me:
>
> create or replace function array_except2(anyarray,anyarray) returns
> anyarray as $$
> select ARRAY(
> (
> select r.elements
> from (
> (select 1,unnest($1))
> union all
> (select 2,unnest($2))
> ) as r (arr, elements)
> group by 1
> having min(arr)=max(arr)
> ))
> $$ language sql strict immutable;
>
> Best regards, Vitalii Tymchyshyn
>
Very neat!
I could see that this function could trivially be modified to handle 3
arrays.
QUESTION: Could this be modified to take an arbitrary number of arrays?
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: GavinFlower@archidevsys.co.nz, tivv00@gmail.com, bricklen@gmail.com, mmoncure@gmail.com
Subject: Re: array_except -- Find elements that are not common to both arrays
In-Reply-To: <4E8AB2D7.2010901@archidevsys.co.nz>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox