Re: Can I use an array with an IN clause?
- From: Dyreatnews@xxxxxxx
- Date: Thu, 03 May 2007 10:14:34 +0200
flarosa <frank@xxxxxxxxxxxxxxx> writes:
Hi,
I want to execute a prepared statement of the form:
SELECT * FROM MyTable WHERE ID IN (1,2,3)
Instead of putting in the literal values (1,2,3) I want to substitute
an array at runtime.
I tried doing this:
SELECT * FROM MyTable WHERE ID IN ?
I tried passing an array of integers as the parameter, but it didn't
work.
I can solve the problem by generating a query of the form "WHERE ID IN
(?,?,?,?)", but I have to create a new query from scratch each time
because the number of integers varies.
Is there some general way to do this?
Don't think so. Someone, please correct me if I'm wrong.
But even with your current approach you may run into problems since
the number of elements in an IN-list often is limited. The limit varies
between databases.
Without knowing more about your app it is a bit hard to say what you
could do instead. I'm guessing that the records you want from MyTable
are somehow related, but your app is hiding this fact from the dbms by
just asking for a seemingly random collection of IDs.
--
dt
.
- References:
- Can I use an array with an IN clause?
- From: flarosa
- Can I use an array with an IN clause?
- Prev by Date: Re: Can I use an array with an IN clause?
- Next by Date: Re: Can I use an array with an IN clause?
- Previous by thread: Re: Can I use an array with an IN clause?
- Next by thread: Re: Can I use an array with an IN clause?
- Index(es):
Relevant Pages
|
|