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.