Re: Array intersection

From: Josh Trutwin <josh(at)trutwins(dot)homeip(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Array intersection
Date: 2007-10-17 18:06:35
Message-ID: 20071017130635.758ad927@sinkhole.intrcomm.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 17 Oct 2007 10:04:21 -0700
David Fetter <david(at)fetter(dot)org> wrote:

<snip>

> CREATE OR REPLACE FUNCTION array_intersect(ANYARRAY, ANYARRAY)
> RETURNS ANYARRAY
> LANGUAGE SQL
> AS $$
> SELECT ARRAY(
> SELECT $1[i] AS "the_intersection"
> FROM generate_series(
> array_lower($1,1),
> array_upper($1,1)
> ) AS i
> INTERSECT
> SELECT $2[j] AS "the_intersection"
> FROM generate_series(
> array_lower($2,1),
> array_upper($2,1)
> ) AS j
> );
> $$;

Doesn't appear to work on 8.1:

psql=> select array_intersect('{1,2,3}', '{2,3,4}');
ERROR: could not determine anyarray/anyelement type because input
has type "unknown"

Hopefully upgrading to 8.3 soon so I'll have another look then.

Thanks,

Josh

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Fetter 2007-10-17 18:26:05 Re: Array intersection
Previous Message Josh Trutwin 2007-10-17 18:02:07 Re: Array intersection