Re: Difference between "in (...)" and "= any(...)" queries when using arrays

From: Richard Huxton <dev(at)archonet(dot)com>
To: francisco(at)npgsql(dot)org
Cc: PgSql General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Difference between "in (...)" and "= any(...)" queries when using arrays
Date: 2009-05-12 08:02:31
Message-ID: 4A092D17.1020608@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Francisco Figueiredo Jr. wrote:
> Hi all!
>
> I was playing with "in (...)" and "= any (...)" queries and found a
> difference between them and I wonder:
>
> why this works:
>
> select * from table_of_integers where integer_column = any (array[5,6]);

This checks if integer_column matches any value in the specified array.

> select * from table_of_integers where integer_column in (array[5,6]);

This checks if integer_column IS an array[5,6] (which it isn't).

You probably want ... IN (5,6)

> SOME is a synonym for ANY. IN is equivalent to = ANY.

I think this is probably talking with respect to sub-queries.

--
Richard Huxton
Archonet Ltd

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joe Kramer 2009-05-12 08:57:07 Re: Unable to access table named "user"
Previous Message Scott Marlowe 2009-05-12 07:55:13 Re: Unable to access table named "user"