From: Bruno Wolff III <bruno@wolff.to>
To: Christian Rusa <christian@rusa.at>
Cc: pgsql-sql@postgresql.org
Subject: Re: Closes Match
Date: Mon, 25 Jul 2005 12:49:52 -0500
Message-ID: <20050725174952.GA23263@wolff.to> (raw)
In-Reply-To: <42E521DF.4000804@rusa.at>
References: <42E521DF.4000804@rusa.at>
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?)?)?)?)?)?$
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, christian@rusa.at
Subject: Re: Closes Match
In-Reply-To: <20050725174952.GA23263@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