X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3EE8C5678F for ; Sat, 26 Feb 2005 19:05:46 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 46127-05 for ; Sat, 26 Feb 2005 19:05:35 +0000 (GMT) Received: from lerami.lerctr.org (lerami.lerctr.org [192.147.25.11]) by svr1.postgresql.org (Postfix) with ESMTP id A0DA65677D for ; Sat, 26 Feb 2005 19:05:40 +0000 (GMT) Received: from lerlaptop.lerctr.org ([192.147.25.14]) by lerami.lerctr.org with esmtpsa (TLSv1:RC4-MD5:128) (Exim 4.50) id 1D57Fx-0000sF-Hu; Sat, 26 Feb 2005 13:05:38 -0600 From: Larry Rosenman To: "Oisin Glynn" Subject: Re: Reverse String in sql or pgplsql Date: Sat, 26 Feb 2005 13:05:39 -0600 User-Agent: KMail/1.7.1 Cc: pgsql-sql@postgresql.org References: <200502241717.14648.aarni@kymi.com> <1109424259.10941.6.camel@localhost.localdomain> <006f01c51c2c$54fb6ef0$a974fea9@homisco.local> In-Reply-To: <006f01c51c2c$54fb6ef0$a974fea9@homisco.local> MIME-Version: 1.0 Content-Disposition: inline Message-Id: <200502261305.40170.ler@lerctr.org> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.01 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200502/332 X-Sequence-Number: 20442 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.