in reply to Simple DBI question, select rows based on an array

Why not do it all in one query:
my $sql = 'SELECT * FROM table WHERE column IN (' . ( join ',', map { +"'$_'" } @array ) . ')';
??
A user level that continues to overstate my experience :-))

Replies are listed 'Best First'.
Re^2: Simple DBI question, select rows based on an array
by ruzam (Curate) on Nov 05, 2009 at 13:44 UTC

    That could get you into trouble with quote problems in @array values or worse sql-injection. At the very least you should use the DBI quote method:

    my $sql = 'SELECT * FROM table WHERE column IN (' . ( join ',', map { $dbi->quote($_) } @array ) . ')';

    Or better, use placeholders

    my $sql = 'SELECT * FROM table WHERE column IN (' . '?' . (',?' x $#array) . ')';