Thread: array in postgre

array in postgre

From
gavaneh
Date:
Hi

suppose we have the following query:
select ....from ...where...and x *=3;

"x" is an integer array,here we want to check whether
"x" contains 3 or not,this is the same as one of
postgre documentaion example,however it doesnt
work.(why???)

should I set any option? any idea?

-thnx



__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail

Re: array in postgre

From
Oliver Elphick
Date:
On Thu, 2004-07-08 at 06:20, gavaneh wrote:
> Hi
>
> suppose we have the following query:
> select ....from ...where...and x *=3;
>
> "x" is an integer array,here we want to check whether
> "x" contains 3 or not,this is the same as one of
> postgre documentaion example,however it doesnt
> work.(why???)
>
> should I set any option? any idea?

From the documentation:

        9.17.3. ANY/SOME (array)
        expression operator ANY (array expression)
        expression operator SOME (array expression)

        The right-hand side is a parenthesized expression, which must
        yield an array value. The left-hand expression is evaluated and
        compared to each element of the array using the given operator,
        which must yield a Boolean result. The result of ANY is "true"
        if any true result is obtained. The result is "false" if no true
        result is found (including the special case where the array has
        zero elements).

        SOME is a synonym for ANY

So in your case:
SELECT ... FROM .. WHERE ... 3 = ANY (x);


Oliver Elphick


Re: array in postgre

From
Tom Lane
Date:
gavaneh <gavaneh@yahoo.com> writes:
> suppose we have the following query:
> select ....from ...where...and x *=3;
> "x" is an integer array,here we want to check whether
> "x" contains 3 or not,this is the same as one of
> postgre documentaion example,however it doesnt
> work.(why???)

Probably because you didn't install the contrib module that supports
the *= operator.

Note that as of 7.4 there is a more standard way to do this.

            regards, tom lane