Re: How to FindNearest

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Alexander Ilyin <a_ilyin(at)ukr(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to FindNearest
Date: 2006-10-03 00:20:49
Message-ID: 20061003002049.GA1490@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Sat, Sep 30, 2006 at 11:43:40 +0300,
Alexander Ilyin <a_ilyin(at)ukr(dot)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 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.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message chrisj 2006-10-03 03:15:56 Assigning a timestamp without timezone to a timestamp with timezone
Previous Message Tom Lane 2006-10-02 21:29:52 Re: Time interval sums