in reply to Re: Comparing an array to a DBI table
in thread Comparing an array to a DBI table

If there are more records than memory will allow, then you might consider reading all the user_ids into a DB_File tied hash. If you list of user_ids to check is not large, then use the 'IN' clause as suggested by merlyn. If your table is very large (or you don't want to use DB_File) AND your list is large, then don't use count(*), but something like this (BTW, I hope you have an index on user_id!):
my $sql = 'select 1 from subscription where user_id = ?'; my $sth = $dbh->prepare($sql); foreach my $userid ... { $sth->execute($userid); my ($exists) = $sth->fetchrow_array; $sth->finish; if ($exists) { ... } }
I also notice you're handling your own errors and probably not using RaiseError on the connect. That's ok, but then you should also check for errors on the prepare and the execute.