Binding multiple arrays for WHERE IN in PostgreSQL
Posted
by
Alec
on Stack Overflow
See other posts from Stack Overflow
or by Alec
Published on 2012-03-20T17:02:04Z
Indexed on
2012/03/20
17:29 UTC
Read the original article
Hit count: 290
So I want to prepare a query something like:
SELECT id FROM users WHERE (branch, cid) IN $1;
But I then need to bind a variable length list of arrays like (('a','b'),('c','d'))
to it. How do I go about doing this? I've tried using ANY but can't seem to get the syntax right.
Cheers,
Alec
Edit:
After some fiddling around, this is valid syntactically:
SELECT id FROM users WHERE (branch, cid) = ANY ($1::text[][]);
and then binding the string '{{a,b},{c,d}}'
to $1
but throws the error "operator does not exist: record = text". Changing 'text' to 'record' then throws "input of anonymous composite types is not implemented". Any ideas?
© Stack Overflow or respective owner