From: Albert REINER <areiner@tph.tuwien.ac.at>
To: pgsql-sql@postgresql.org
Subject: Re: Re: select substr???
Date: Tue, 10 Apr 2001 18:38:15 +0200
Message-ID: <20010410183815.C3219@frithjof> (raw)
In-Reply-To: <NBBBLHOPPPPCHCIABAFGOEDEDKAA.tim@celestialdesign.co.uk>
References: <NBBBLHOPPPPCHCIABAFGOEDEDKAA.tim@celestialdesign.co.uk>
On Mon, Apr 09, 2001 at 06:05:55PM +0100, Tim Johnson wrote:
> Hi,
>
> I have postgres 6.x (where x is something).
>
> I have the following list of data
>
> data
> --------
> ABC*
> ABC
> ABC-
...
> what I want to do is 'select distinct(data) [ignoring non alphanumeric
> characters] order by data'
somewhere I use the following, which might be adapted to do what you
want. I am sure there are more elegant ways of doing this, though.
create function ComparisonString(text) returns text as '
declare
t text;
r text;
c char;
ns bool;
begin
if $1 is null then
return NULL;
end if;
t = lower(trim(both $1));
r = '''';
ns = false;
for i in 1 .. char_length(t) loop
c = substring(t from i for 1);
if c = '' '' then
if ns then
r = r || '' '';
end if;
ns = false;
else
if position(c in ''abcdefghijklmnopqrstuvwxyz0123456789'') > 0 then
r = r || c;
ns = true;
end if;
end if;
end loop;
return trim(both r);
end;
' language 'plpgsql' with (IsCachable);
Albert.
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: areiner@tph.tuwien.ac.at
Subject: Re: select substr???
In-Reply-To: <20010410183815.C3219@frithjof>
References: <NBBBLHOPPPPCHCIABAFGOEDEDKAA.tim@celestialdesign.co.uk> <20010410183815.C3219@frithjof>
* 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