Re: Reverse String in sql or pgplsql

From: Larry Rosenman <ler(at)lerctr(dot)org>
To: "Oisin Glynn" <me(at)oisinglynn(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Reverse String in sql or pgplsql
Date: 2005-02-26 19:05:39
Message-ID: 200502261305.40170.ler@lerctr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Saturday 26 February 2005 11:55 am, Oisin Glynn wrote:
> Did some searching on forums archives to no avail, I found a PL/Perl
> example but would like to do this in plpgsql if possible. Does somebody
> have this sitting around, I just dont want to reinvent the wheel. But if
> need to I will.
>
> Thanks in advance,
>
> Oisin
CREATE FUNCTION reverse(text) RETURNS text
AS $_$
DECLARE
original alias for $1;
reverse_str text;
i int4;
BEGIN
reverse_str := '';
FOR i IN REVERSE LENGTH(original)..1 LOOP
reverse_str := reverse_str || substr(original,i,1);
END LOOP;
RETURN reverse_str;
END;$_$
LANGUAGE plpgsql IMMUTABLE;

from a posting a while back.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bradley Miller 2005-02-26 20:05:42 Re: Reverse String in sql or pgplsql
Previous Message Bruno Wolff III 2005-02-26 18:01:08 Re: diference in dates in minutes