Re: large query by offset and limt

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: finecur <finecur(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: large query by offset and limt
Date: 2008-05-03 18:34:38
Message-ID: 481CB03E.3050906@postnewspapers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

finecur wrote:
> Hi, I am ruuning a database behind a webserver and there is a table
> which is huge. I need to pull data from this table and send to user
> through http. If I use
>
> select * from huge_table where userid = 100
>
> It will return millions of records which exhuasts my server's memory.

> Is there a better way to do this?

Consider using database cursors. Set up by beginning a transaction and
issuing the statement:

DECLARE huge_table_curs CURSOR FOR
SELECT * FROM huge_table WHERE userid = 100;

... then to get results, just execute:

FETCH 1000 FROM huge_table_curs;

--
Craig Ringer

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Craig Ringer 2008-05-03 19:04:56 Re: clustering without locking
Previous Message Tom Lane 2008-05-03 18:33:18 Re: clustering without locking