in reply to DBI question with placeholders and IN

Snippet from perldoc DBI:

Also, placeholders can only represent single scalar
values.  For example, the following statement won't
work as expected for more than one value:

"SELECT name, age FROM people WHERE name IN (?)"    # wrong

If you only need a count, you can always do

my %uniq = ();
++$uniq{$_} for @values;
$count = 0 + keys %uniq;

But you need to be absolutely sure all the @values exist in your table (and to be 100% sure, you must check)

There's little you can do. I'd use a direct prepare() and an execute() each time. If you manage to pass multiple scalars with a single ?, it wouldn't be portable anyway.

--
my $twocents;
  • Comment on Re: DBI question with placeholders and IN