Re: [pgsql-advocacy] Function which gives back the nearest neighbours

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>
Cc: Virgile Beddok <virgile(dot)beddok(at)igd(dot)fraunhofer(dot)de>, pgsql-novice(at)postgresql(dot)org, pgsql-advocacy(at)postgresql(dot)org, pgsql-admin(at)postgresql(dot)org
Subject: Re: [pgsql-advocacy] Function which gives back the nearest neighbours
Date: 2005-03-27 16:36:53
Message-ID: 20050327163653.GH9280@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-advocacy pgsql-novice

On Sun, Mar 27, 2005 at 13:24:34 +0800,
Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au> wrote:
> >I'm looking for an existing function which allows me to search the nearest
> >neighbours of the requested value.
>
> Well you could try something like:
>
> SELECT * FROM table ORDER BY ABS(val - 2) LIMIT 1;
>
> That doesn't get you all the way there, but it's an idea...

For multidimensional objects you can do the same thing with a distance
metric function. It will be relatively slow since this won't be indexable
and will require a sort of all of the values. If you have some bound on
how far apart points can be, then you might be able to limit the set
of candidate points using an indexable search.

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message dedy 2005-03-28 05:48:47 Re: How to move the ...
Previous Message Tom Lane 2005-03-27 16:32:12 Re: [NOVICE] [pgsql-advocacy] Function which gives back the nearest neighbours

Browse pgsql-advocacy by date

  From Date Subject
Next Message Magnus Hagander 2005-03-27 18:14:13 Re: postgresQL.org "Latest News" or "Latest Product"?
Previous Message Tom Lane 2005-03-27 16:32:12 Re: [NOVICE] [pgsql-advocacy] Function which gives back the nearest neighbours

Browse pgsql-novice by date

  From Date Subject
Next Message Stephen Choularton 2005-03-27 19:27:03 initial password
Previous Message Tom Lane 2005-03-27 16:32:12 Re: [NOVICE] [pgsql-advocacy] Function which gives back the nearest neighbours