PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Michael Peppler <mpeppler at MBAY dot NET>
Subject: Re: Queries n rows at a time
Date: Jul 15 1998 2:42PM

Simon Yaminian writes:
 > 
 > > 
 > > It depends on the query.  If there's a unique field, you can use it to 
 > > chop your query into blocks.  eg
 > > 
 > >    select id, name, address from employees
 > >    where state='NY' and id>$x and id<=$x+100
 > > 
 > > 
 > 	Thanks for your reply.
 > Suppose you have the following query:
 > 
 > 	select * from employees
 > 
 > How can you get those let's say 200 at a time and suppose you have 20,000
 > employees. The idea is, instead of waiting let's say 20 seconds to complete
 > the query, wait .2 second at a time and get some data to work with in the
 > meantime.

If you have an appropriate index you don't have to wait 20 seconds to
get data back.

But assuming you have a unique index on employee_id, you could do:

set rowcount 200

$data = $dbh->sql("select * from employee");
# do something with the data...
$last_employee_id = $data[$#{$data}]->[0];    # assume employee_id is
					      # column 0
$data = $dbh->sql("select * from employee where employee_id >
$last_employee_id");

etc...

You can put this in a loop to make it nicer.

Michael
-- 
Michael Peppler         -||-  Data Migrations Inc.
mpeppler@datamig.com    -||-  http://www.mbay.net/~mpeppler
Int. Sybase User Group  -||-  http://www.isug.com