in reply to DBI select IN Array

Perl does not execute Perl inside a Perl string. eg. print "1 + 1"; will output "1 + 1" and not "2". Set up your SQL string properly and it will be fine.

my @tagList = ('red', 'black'); my $sql = 'SELECT table FROM tags WHERE tag IN (' . join (', ', map {'?'} @tagList) . ')'; my $ID = $dbh->selectall_arrayref ($sql, undef, @tagList);

Update: Fix typo on last line s/taglist/tagList/; I never use camelCase in variable names so it was easy to miss :-)

Replies are listed 'Best First'.
Re^2: DBI select IN Array
by Tux (Canon) on Feb 20, 2019 at 15:07 UTC

    Note that some/many databases have a limit on the length of that list. Did you try with 1_892_102_321 entries?

    YMMV

    Just saying this doesn't scale well


    Enjoy, Have FUN! H.Merijn
Re^2: DBI select IN Array
by Anonymous Monk on Feb 20, 2019 at 09:42 UTC

    Thank you Hippo. I can see the Perl-related issue. However, your solution produces an empty result, while if I use the following $sql, I can get the expected results. What do you think?

    my $sql = "SELECT table FROM tags WHERE tag IN ('red','black')"; my $ID = $dbh->selectall_arrayref ($sql);

      It was a typo in the args on the last line which I've fixed now. If you were running under strict your code would have picked that up. Try that and see how you get on. If you still have problems please consider providing an SSCCE.

        Shame on me. Thanks, it works.