Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 495AE9FB2BF for ; Tue, 3 Oct 2006 08:43:53 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 75830-01 for ; Tue, 3 Oct 2006 11:43:46 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 0DC8F9FB2BE for ; Tue, 3 Oct 2006 08:43:46 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from kitty.ukr.net (kitty.ukr.net [212.42.65.67]) by svr4.postgresql.org (Postfix) with ESMTP id 53C635AF861 for ; Tue, 3 Oct 2006 11:43:44 +0000 (GMT) Received: from mail by kitty.ukr.net with local ID 1GUigW-000K1a-7F ; Tue, 03 Oct 2006 14:43:40 +0300 Received: from [212.9.255.98] by e.ukr.net with HTTP; Tue, 03 Oct 2006 11:43:40 +0000 (GMT) From: "Alexander Ilyin" To: "Bruno Wolff III" Cc: pgsql-sql@postgresql.org Reply-To: "Alexander Ilyin" Subject: Re: How to FindNearest Mime-Version: 1.0 X-Mailer: mPOP Web-Mail 2.19 advanced X-Originating-IP: 192.168.5.175 via proxy [212.9.255.98] In-Reply-To: <20061003002049.GA1490@wolff.to> Content-Type: text/plain; charset=windows-1251 Content-Transfer-Encoding: 8bit Message-Id: Date: Tue, 03 Oct 2006 14:43:40 +0300 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.111 tagged_above=0 required=5 tests=RATWARE_MPOP_WEBMAIL X-Spam-Level: X-Archive-Number: 200610/16 X-Sequence-Number: 26405 -----Original Message----- From: Bruno Wolff III To: Alexander Ilyin Date: Mon, 2 Oct 2006 19:20:49 -0500 Subject: Re: How to FindNearest > On Sat, Sep 30, 2006 at 11:43:40 +0300, > Alexander Ilyin wrote: > > > > Suppose we have huge table. On the screen we need to show contents of that table in the Grid and under that Grid user can input in TextBox some letters. OnChange of this TextBox we need to make current row selection in the Grid on the row with value of some column nearest to the user input in the TextBox. > > > > How this can be implemented in PostgreSQL? > > You can search for the row with the closest above and the row with the > closest below and then return whichever these is closer. (Remember to handle > the case where the target is larger or smaller than all values in the > database.) You can use ORDER BY and LIMIT 1 and an appropiiate WHERE > clause (something like columnname >= targetvalue) to do this. > > Thank you for your great idea. But how it can be used for positioning the cursor in the already existed ResultSet? Using your idea I can found the closest to targetvalue row but not its position in my ResultSet. Anyway thank you for your idea it is very useful by itself. Also I can solve my problem using your idea and emulating the movement in my existed ResultSet. Even better - no need to store the large RS between cursor movements. Just each time I need to fetch the all visible rows.