pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Closes Match
3+ messages / 3 participants
[nested] [flat]

* Closes Match
@ 2005-07-25 17:31  Christian Rusa <christian@rusa.at>
  0 siblings, 1 reply; 3+ messages in thread

From: Christian Rusa @ 2005-07-25 17:31 UTC (permalink / raw)
  To: pgsql-sql

Hi there,

I want to match a string against the database and get the closest 
(shorter) match.
I was asking myself if its possible to realise this in SQL.

So if the string is:
abcdefg

And in the database are entries like:
a
ab
abc

I just want to get back 'abc'.

I looked around in the internet and the documentation but found no solution.

Cheers Christian

Attachments:

  smime.p7s (application/x-pkcs7-signature, 3.1K) download

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Closes Match
@ 2005-07-25 17:49  Bruno Wolff III <bruno@wolff.to>
  parent: Christian Rusa <christian@rusa.at>
  0 siblings, 1 reply; 3+ messages in thread

From: Bruno Wolff III @ 2005-07-25 17:49 UTC (permalink / raw)
  To: Christian Rusa <christian@rusa.at>; +Cc: pgsql-sql

On Mon, Jul 25, 2005 at 19:31:11 +0200,
  Christian Rusa <christian@rusa.at> wrote:
> Hi there,
> 
> I want to match a string against the database and get the closest 
> (shorter) match.
> I was asking myself if its possible to realise this in SQL.
> 
> So if the string is:
> abcdefg
> 
> And in the database are entries like:
> a
> ab
> abc
> 
> I just want to get back 'abc'.
> 
> I looked around in the internet and the documentation but found no solution.

You could ORDER BY the length of the strings descending and use LIMIT
to return only one row.

You can write a regular expression to do the matching. Something like:
^(a(b(c(d(e(fg?)?)?)?)?)?$



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Closes Match
@ 2005-07-25 18:57  Jonathan Lam <lamj@spawar.navy.mil>
  parent: Bruno Wolff III <bruno@wolff.to>
  0 siblings, 0 replies; 3+ messages in thread

From: Jonathan Lam @ 2005-07-25 18:57 UTC (permalink / raw)
  To: pgsql-sql

unsubscribe
-----Original Message-----
From: pgsql-sql-owner@postgresql.org
[mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Bruno Wolff III
Sent: Monday, July 25, 2005 10:50 AM
To: Christian Rusa
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] Closes Match

On Mon, Jul 25, 2005 at 19:31:11 +0200,
  Christian Rusa <christian@rusa.at> wrote:
> Hi there,
> 
> I want to match a string against the database and get the closest 
> (shorter) match.
> I was asking myself if its possible to realise this in SQL.
> 
> So if the string is:
> abcdefg
> 
> And in the database are entries like:
> a
> ab
> abc
> 
> I just want to get back 'abc'.
> 
> I looked around in the internet and the documentation but found no
solution.

You could ORDER BY the length of the strings descending and use LIMIT
to return only one row.

You can write a regular expression to do the matching. Something like:
^(a(b(c(d(e(fg?)?)?)?)?)?$

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2005-07-25 18:57 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-07-25 17:31 Closes Match Christian Rusa <christian@rusa.at>
2005-07-25 17:49 ` Bruno Wolff III <bruno@wolff.to>
2005-07-25 18:57   ` Jonathan Lam <lamj@spawar.navy.mil>

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