X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 979E63A3D50 for ; Fri, 5 Nov 2004 18:09:50 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 10357-07 for ; Fri, 5 Nov 2004 18:09:47 +0000 (GMT) Received: from bt2.jordan.pl (unknown [62.121.132.241]) by svr1.postgresql.org (Postfix) with ESMTP id 2291E3A3D36 for ; Fri, 5 Nov 2004 18:09:44 +0000 (GMT) Received: from localhost (localhost [127.0.0.1]) by bt2.jordan.pl (Postfix) with ESMTP id 6E6E519C009; Fri, 5 Nov 2004 19:09:38 +0100 (CET) Received: from bt2.jordan.pl ([127.0.0.1]) by localhost (bt2 [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 24053-10; Fri, 5 Nov 2004 19:09:37 +0100 (CET) Received: from [192.168.24.1] (81-186-238-81.bezlicznika.pl [81.186.238.81]) by bt2.jordan.pl (Postfix) with ESMTP id 2339D19C002; Fri, 5 Nov 2004 19:09:37 +0100 (CET) Message-ID: <418BC1F3.7080205@klaster.net> Date: Fri, 05 Nov 2004 19:09:55 +0100 From: Tomasz Myrta User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) X-Accept-Language: pl, en-us, en MIME-Version: 1.0 To: Andras Kutrovics Cc: pgsql-sql@postgresql.org Subject: Re: Simple SQL Question References: <418BB051.6070808@freemail.hu> In-Reply-To: <418BB051.6070808@freemail.hu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at bt2.jordan.pl X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200411/51 X-Sequence-Number: 19370 > Hi All! > > In one of my application, I would like to implement incremental > fetching. The problem is that I would like to run it > from a stateless application server, so I have to tell where > to begin fetching data. It is simple for a table which has single column > primary key, but causes difficulties (at least for me) in > a more-column primary key.. > > Let say I have a table wich has the primary key: itemkey,location > > table1 > ------ > itemkey > location > ... > -------- > > > select * from table1 LIMIT x > > gives me the first x row of the result. > After that, I save the last value, and next time, I adjust > the query as > > select * from table1 where itemkey>:lastvalue LIMIT x Why do you complicate it so much? Everything you need is: select * from table1 LIMIT x select * from table1 LIMIT x OFFSET x select * from table1 LIMIT x OFFSET 2*x Remember to sort rows before using limit/offset. Regards, Tomasz Myrta