Re: best match question: please help

From: Manfred Koizar <mkoi-pg(at)aon(dot)at>
To: "Raouf" <aimeur(at)prodigy(dot)net>
Cc: <pgsql-novice(at)postgresql(dot)org>
Subject: Re: best match question: please help
Date: 2002-07-04 13:18:12
Message-ID: jsh8iukoq2epjj3bcta30q0gfcsrpqnvrk@4ax.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Thu, 4 Jul 2002 00:18:02 -0700, "Raouf" <aimeur(at)prodigy(dot)net> wrote:
>table snmpOids
>---------------------------------------------------------------------------------
>id | objectId | objectDescr
>---------------------------------------------------------------------------------
>1 | 1.3.6 | name1
>2 | 1.3.6.1 | name2
>3 | 1.3.6.1.2 | name3
>4 | 1.3.6.1.2.1 | name4
>5 | 1.0.2.3.1 | name5
>6 | 1.1.2.3.1 | name6
>
>type is VARCHAR for all the columns of snmpOids.
>
>Let's say that I have an objectId equal to 1.3.6.1.2.1.1.1 and
>I want to get back from my query the best match on the objectId,
>which is 1.3.6.1.2.1 (closest objectId to 1.3.6.1.2.1.1.1 ).

SELECT *
FROM snmpOids
WHERE '1.3.6.1.2.1.1.1' LIKE objectId || '%'
ORDER BY objectId DESC
LIMIT 1;

should do what you need, but don't tell anybody you got that from me
when it kills your performance ;-)

Servus
Manfred

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message April L 2002-07-04 14:46:20 KEYEXISTS function
Previous Message Raouf 2002-07-04 07:18:02 best match question: please help