Another way to construct a reasonable "IN" clause is to use the
DBI::quote method:
| my @vals = ('foo', "bar", "baz's");
| my $set = join ', ', map $dbh->quote($_), @vals;
| my $sql = "SELECT whatever FROM wherever WHERE somecolumn IN ($set)";
Note that this will properly handle the single quote in the third
value.
Using multiple placeholders will also work, although I'd be surprised
if the total number of placeholders in any given statement can be all
that high.
Finally, consider other ways of solving the problem. Are you using
this set often? If so, consider putting it into a table in the
database, and use a subquery to generate the IN clause, or join
against the primary table.
t.
- How do I form an acceptable string for an IN clause? Jim Lynch
- Re: How do I form an acceptable string for an IN ... Maria Quinn
- Re: How do I form an acceptable string for an IN ... Ronald J Kimball
- Re: How do I form an acceptable string for an IN ... Peter J . Holzer
- Re: How do I form an acceptable string for an... Graham Barr
- Re: How do I form an acceptable string fo... William R. Mussatto
- Re: How do I form an acceptable strin... Ronald J Kimball
- Re: How do I form an acceptable ... Jeff Zucker
- Re: How do I form an accepta... Jeff Zucker
- Re: How do I form an acceptable string for an IN ... Tony Foiani
- Re: How do I form an acceptable string for an... Michael A. Chase
- Re: How do I form an acceptable string for an IN ... Jim Lynch
