Lists: | pgsql-general |
---|
From: | "Christopher Murtagh" <christopher(dot)murtagh(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Array comparison - subset |
Date: | 2006-09-01 15:55:32 |
Message-ID: | 92fbb7920609010855y280276cco9eb4ea502d53fe83@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
Greetings folks,
I've got a function that returns and array $foo, and an array $bar.
Is there an elegant way to test if $bar is a subset of $foo? I've been
looking through the docs and haven't found anything. Am I missing
something obvious, or am I out of luck?
Cheers,
Chris
From: | Michael Fuhr <mike(at)fuhr(dot)org> |
---|---|
To: | Christopher Murtagh <christopher(dot)murtagh(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Array comparison - subset |
Date: | 2006-09-03 04:48:09 |
Message-ID: | 20060903044809.GA65544@winnie.fuhr.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
On Fri, Sep 01, 2006 at 11:55:32AM -0400, Christopher Murtagh wrote:
> I've got a function that returns and array $foo, and an array $bar.
> Is there an elegant way to test if $bar is a subset of $foo? I've been
> looking through the docs and haven't found anything. Am I missing
> something obvious, or am I out of luck?
In the specific case of integer arrays you could use contrib/intarray.
test=> SELECT ARRAY[1, 2, 3, 4] @ ARRAY[1, 3];
?column?
----------
t
(1 row)
test=> SELECT ARRAY[1, 2, 3, 4] @ ARRAY[1, 5];
?column?
----------
f
(1 row)
In 8.2 the above example will work in the stock installation for
arrays of any type (i.e., with operands of type anyarray).
--
Michael Fuhr
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Michael Fuhr <mike(at)fuhr(dot)org> |
Cc: | Christopher Murtagh <christopher(dot)murtagh(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Array comparison - subset |
Date: | 2006-09-03 04:59:08 |
Message-ID: | 9051.1157259548@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
Michael Fuhr <mike(at)fuhr(dot)org> writes:
> test=> SELECT ARRAY[1, 2, 3, 4] @ ARRAY[1, 3];
> ?column?
> ----------
> t
> (1 row)
> In 8.2 the above example will work in the stock installation for
> arrays of any type (i.e., with operands of type anyarray).
[ blink... ] When did that get in, and why don't I see it in the
documentation? The operand order seems exactly backward considering
that all the pre-existing @ operators are "contained in", not
"contains". Should we flip this around before it's too late?
regards, tom lane
From: | Michael Fuhr <mike(at)fuhr(dot)org> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Christopher Murtagh <christopher(dot)murtagh(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Array comparison - subset |
Date: | 2006-09-03 13:32:04 |
Message-ID: | 20060903133204.GA67646@winnie.fuhr.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
On Sun, Sep 03, 2006 at 12:59:08AM -0400, Tom Lane wrote:
> Michael Fuhr <mike(at)fuhr(dot)org> writes:
> > test=> SELECT ARRAY[1, 2, 3, 4] @ ARRAY[1, 3];
> > ?column?
> > ----------
> > t
> > (1 row)
>
> > In 8.2 the above example will work in the stock installation for
> > arrays of any type (i.e., with operands of type anyarray).
>
> [ blink... ] When did that get in, and why don't I see it in the
> documentation?
Looks like it arrived with the gin code.
http://archives.postgresql.org/pgsql-committers/2006-05/msg00007.php
http://developer.postgresql.org/cvsweb.cgi/pgsql/src/include/catalog/pg_operator.h.diff?r1=1.142&r2=1.143
> The operand order seems exactly backward considering
> that all the pre-existing @ operators are "contained in", not
> "contains". Should we flip this around before it's too late?
I'd favor consistency, although I see that contrib/intarray has had
it backwards for a long time :-(
--
Michael Fuhr
From: | "Christopher Murtagh" <christopher(dot)murtagh(at)gmail(dot)com> |
---|---|
To: | "Michael Fuhr" <mike(at)fuhr(dot)org> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Array comparison - subset |
Date: | 2006-09-04 18:42:45 |
Message-ID: | 92fbb7920609041142r47b145fep6199679f63873f8f@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
On 9/3/06, Michael Fuhr <mike(at)fuhr(dot)org> wrote:
> On Fri, Sep 01, 2006 at 11:55:32AM -0400, Christopher Murtagh wrote:
> > I've got a function that returns and array $foo, and an array $bar.
> > Is there an elegant way to test if $bar is a subset of $foo? I've been
> > looking through the docs and haven't found anything. Am I missing
> > something obvious, or am I out of luck?
>
> In the specific case of integer arrays you could use contrib/intarray.
Cool. This is exactly what I needed. Thanks a bunch!
Cheers,
Chris