pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Vitalii Tymchyshyn <tivv00@gmail.com>
To: 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: Fri, 30 Sep 2011 15:23:11 +0300
Message-ID: <4E85B4AF.2090104@gmail.com> (raw)
In-Reply-To: <CAGrpgQ-Zo6FOtc=NtY-4wXcnYqQRgcRLDR3BGQk2nAXpW46rzA@mail.gmail.com>
References: <CAGrpgQ8YkMVpN1scWYbqBW+fdNhSpXFd9T7YqxmGCJKT3XHZnA@mail.gmail.com>
	<CAHyXU0wVZ+0A7FCvYNcK_r9UTqutgpjE8MQHXAmb2uv7=0-QZQ@mail.gmail.com>
	<CAGrpgQ-Zo6FOtc=NtY-4wXcnYqQRgcRLDR3BGQk2nAXpW46rzA@mail.gmail.com>

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



view thread (11+ messages)  latest in thread

Message-ID: <4E85B4AF.2090104@gmail.com>
Permalink:  ../4E85B4AF.2090104@gmail.com/
Also on:    postgresql.org/message-id/4E85B4AF.2090104@gmail.com

 · 

reply

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: 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: <4E85B4AF.2090104@gmail.com>

* 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