Re: How to FindNearest - Mailing list pgsql-sql

From Bruno Wolff III
Subject Re: How to FindNearest
Date
Msg-id 20061003002049.GA1490@wolff.to
Whole thread Raw
In response to How to FindNearest  ("Alexander Ilyin" <a_ilyin@ukr.net>)
Responses Re: How to FindNearest  ("Alexander Ilyin" <a_ilyin@ukr.net>)
List pgsql-sql
On Sat, Sep 30, 2006 at 11:43:40 +0300, Alexander Ilyin <a_ilyin@ukr.net> 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
caninput in TextBox some letters. OnChange of this TextBox we need to make current row selection in the Grid on the row
withvalue 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.


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Time interval sums
Next
From: chrisj
Date:
Subject: Assigning a timestamp without timezone to a timestamp with timezone