Re: Limiting the number of records in Execute Query

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Raj Shooj-Q16466 <shooj(at)motorola(dot)com>
Cc: "'pgsql-odbc(at)postgresql(dot)org'" <pgsql-odbc(at)postgresql(dot)org>
Subject: Re: Limiting the number of records in Execute Query
Date: 2003-09-12 14:24:05
Message-ID: 10820.1063376645@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-odbc

Raj Shooj-Q16466 <shooj(at)motorola(dot)com> writes:
> I am retrieving 1 million records by executing the sql query
> SELECT * FROM myTable ORDER BY sub_id LIMIT 20000 OFFSET <num>;
> in a loop, incrementing <num> every time by 20000.

Wouldn't it be better to use a cursor?

BEGIN;
DECLARE c CURSOR FOR SELECT * FROM myTable ORDER BY sub_id;
FETCH 20000 FROM c;
... repeat FETCH as needed ...
COMMIT;

regards, tom lane

In response to

Browse pgsql-odbc by date

  From Date Subject
Next Message Greg Campbell 2003-09-12 15:44:53 ADO Server Cursors and OID
Previous Message administrators 2003-09-12 14:07:30 visual basic