Обсуждение: Re: select substr???
Hi, I have postgres 6.x (where x is something). I have the following list of data data -------- ABC* ABC ABC- ABC+ ABC QWE~ ASD+ ASD# KLASDHK- KLASDHK+ KLASDHK KLASDHK* what I want to do is 'select distinct(data) [ignoring non alphanumeric characters] order by data' is there a way to do that? Changing the data stored in the table is not an option as the suffixes are needed elsewhere.. Please help !! Thanks, Tim.
Tim Johnson writes: > Hi, > > I have postgres 6.x (where x is something). > > I have the following list of data > > data > -------- > ABC* > ABC > ABC- > ABC+ > ABC > QWE~ > ASD+ > ASD# > KLASDHK- > KLASDHK+ > KLASDHK > KLASDHK* > > > what I want to do is 'select distinct(data) [ignoring non alphanumeric > characters] order by data' Write a function that strips off the suffixes and do 'select distinct voodoo(data) ...'. -- Peter Eisentraut peter_e@gmx.net http://yi.org/peter-e/
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.