Thread: Question about the ANY operator
I'm having trouble figuring out the ANY operator.. Basically I want to return rows that match any of the given IDs:
select Name from Users where UserId = ANY ARRAY['948aeda5-ffff-41bd-af4e-71d1c740db76', '5ee315ea-7ef6-4fa5-809a-dc9931a01ed1']::uuid[];
I get the syntax error:
ERROR: syntax error at or near "ARRAY"
LINE 1: ...* from Users where UserId = ANY ARRAY['948...
I know I could just use a bunch of OR clauses, but I want to pass in this array as a variable. Any clue as to what I'm doing wrong?
Mike
select Name from Users where UserId = ANY ARRAY['948aeda5-ffff-41bd-af4e-71d1c740db76', '5ee315ea-7ef6-4fa5-809a-dc9931a01ed1']::uuid[];
I get the syntax error:
ERROR: syntax error at or near "ARRAY"
LINE 1: ...* from Users where UserId = ANY ARRAY['948...
I know I could just use a bunch of OR clauses, but I want to pass in this array as a variable. Any clue as to what I'm doing wrong?
Mike
On Mon, Dec 21, 2009 at 02:46:59AM -0800, Mike Christensen wrote: > I'm having trouble figuring out the ANY operator.. Basically I want to > return rows that match any of the given IDs: > > select Name from Users where UserId = ANY > ARRAY['948aeda5-ffff-41bd-af4e-71d1c740db76', > '5ee315ea-7ef6-4fa5-809a-dc9931a01ed1']::uuid[]; The syntax is '= ANY(foo)', you're missing the parenthesis. Have a nice day, -- Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/ > Please line up in a tree and maintain the heap invariant while > boarding. Thank you for flying nlogn airlines.
Attachment
Uggghhh.. Yea I figured that out about 30 seconds before your reply.. I guess it would be way too much trouble for Postgres to just say "Expected parenthesis" or some sort of error that would actually be helpful to noobs like me.
But thanks :)
Mike
But thanks :)
Mike
On Mon, Dec 21, 2009 at 2:49 AM, Martijn van Oosterhout <kleptog@svana.org> wrote:
On Mon, Dec 21, 2009 at 02:46:59AM -0800, Mike Christensen wrote:The syntax is '= ANY(foo)', you're missing the parenthesis.
> I'm having trouble figuring out the ANY operator.. Basically I want to
> return rows that match any of the given IDs:
>
> select Name from Users where UserId = ANY
> ARRAY['948aeda5-ffff-41bd-af4e-71d1c740db76',
> '5ee315ea-7ef6-4fa5-809a-dc9931a01ed1']::uuid[];
Have a nice day,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while
> boarding. Thank you for flying nlogn airlines.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
iD8DBQFLL1KvIB7bNG8LQkwRAsqUAJ4qkzz2KCMsI1x6RceWnEUQJMzcVQCeNF3A
VqtBQnx0dJDPBxAS2f74/7M=
=S0HC
-----END PGP SIGNATURE-----