Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Re: Re: fethrow_array return value

by Roger (Parson)
on Jan 10, 2004 at 01:03 UTC ( #320263=note: print w/replies, xml ) Need Help??


in reply to Re: Re: fethrow_array return value
in thread fetchrow_array return value

In the case in question, there was no need to get the actual data, the only question was if there were any rows returned.

In that case you could do with a different approach -

my $sql = "SELECT count(*) FROM table WHERE .... "; ...

This query will return a single row containing the count of matching rows (row count) in the table. I believe this is the most efficient and portable way to determine the number of rows, and the fastest too.

Replies are listed 'Best First'.
Re: Re: Re: Re: fethrow_array return value
by runrig (Abbot) on Jan 10, 2004 at 02:13 UTC
    and the fastest too.

    Perhaps the most intuitive, but not necessarily the fastest (update: the fastest way to determine if there are any rows, that is, as the OP asked for). If your database is able to return rows as they're found (i.e. it doesn't have to return the entire result set like MySQL), and if there are any rows, it can be faster to do a select 1 from table... than to do a select count(*) from table....

      I meant the fastest way to determine the number of rows though.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://320263]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2019-08-19 20:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If you were the first to set foot on the Moon, what would be your epigram?






    Results (141 votes). Check out past polls.

    Notices?