Re: last word in text - Mailing list pgsql-general

From Nigel J. Andrews
Subject Re: last word in text
Date
Msg-id Pine.LNX.4.21.0301152153250.5255-100000@ponder.fairway2k.co.uk
Whole thread Raw
In response to Re: last word in text  (Gregory Seidman <gss+pg@cs.brown.edu>)
List pgsql-general
On Wed, 15 Jan 2003, Gregory Seidman wrote:

> Ian Harding sez:
> } I am certain it can, but you could make pltcl available (if you have
> } the rights) by typing
> }
> } createlang 'pltcl' yourdatabasename
> }
> } at the command prompt.
>
> I have the rights, but I don't seem to have the library. I don't think I
> compiled it when I configured/built postgresql in the first place.
>
> % createlang --username=postgres --pglib=/Volumes/Database/postgresql/lib 'pltcl' template0
> ERROR:  stat failed on file '/Volumes/Database/postgresql/lib/pltcl': No such file or directory
> createlang: language installation failed
> %


select substring(rtrim(' ', a.sentence) from '\w+$') from atable a;

Well at least for 7.3.x I can't remember but I presume you're still on an older
production release.


create function last_word ( text ) returns text as '
  declare
    frompos integer;
    ostr alias for $1;
  begin
    while strpos($ostr, ' ') > 0 loop
      frompos := strpos($ostr, ' ') + 1;
      ostr := substring($ostr, $frompos);
    end loop;
    return $ostr;
  end;
' language 'plpgsql';

It ain't pretty, it ain't perfect and it ain't optimised but it might do as a
first draft for you.


--
Nigel J. Andrews


pgsql-general by date:

Previous
From: "Jim Buttafuoco"
Date:
Subject: Re: CREATE TYPE example needed
Next
From: Tom Lane
Date:
Subject: Re: Problem handling timezones