in reply to How to fetch the size of the resultset from a DBI query?

in sql:

"SELECT COUNT(*) FROM people"

doing the same in perl would be horribly inefficient, unless you're going to do something else with the results afterwards. here's a minimal version anyway, in case for some reason select count isn't possible:

my $records = $dbh->selectcol_arrayref('SELECT location FROM people'); my $peoplecount = scalar(@$records);

update: curses... redundant again.

Replies are listed 'Best First'.
Re: Re: How to fetch the size of the resultset from a DBI query?
by seesik (Initiate) on Sep 12, 2001 at 23:37 UTC
    be extremely careful with this approach, as it actually caches your result set in memory. if you're querying against 400 GB of data, you might not want that entire resultset stored locally ;)
    revision uno: hmm, that's a selectcol_arrayref which only caches the first column's values IIRC (which still might be relatively large), not selectall_arrayref which caches the entire resultset