pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruno Wolff III <bruno@wolff.to>
To: Alexander Ilyin <a_ilyin@ukr.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: How to FindNearest
Date: Mon, 2 Oct 2006 19:20:49 -0500
Message-ID: <20061003002049.GA1490@wolff.to> (raw)
In-Reply-To: <E1GTaRg-0009G5-H9@kitty.ukr.net>
References: <E1GTaRg-0009G5-H9@kitty.ukr.net>

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 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.



view thread (6+ messages)  latest in thread

Message-ID: <20061003002049.GA1490@wolff.to>
Permalink:  ../20061003002049.GA1490@wolff.to/
Also on:    postgresql.org/message-id/20061003002049.GA1490@wolff.to

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: bruno@wolff.to, a_ilyin@ukr.net
  Subject: Re: How to FindNearest
  In-Reply-To: <20061003002049.GA1490@wolff.to>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox