Re: string reverse fucntion? - Mailing list pgsql-general

From Shoaib Mir
Subject Re: string reverse fucntion?
Date
Msg-id bf54be871002090341m4b4b88cdxb725e25f4544307@mail.gmail.com
Whole thread Raw
In response to Re: string reverse fucntion?  (Richard Huxton <dev@archonet.com>)
Responses Re: string reverse fucntion?  (Vincenzo Romano <vincenzo.romano@notorand.it>)
List pgsql-general
On Tue, Feb 9, 2010 at 10:31 PM, Richard Huxton <dev@archonet.com> wrote:
On 09/02/10 09:51, AI Rumman wrote:
I am using Postgresql 8.1.

I have to reverse a string like 'abc' to 'cba'.

Is there any function to do this?

Nothing built-in, but you can write your own easily enough in plpgsql - google a bit for examples.


From an old posting:

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;
-- 
Shoaib Mir
http://shoaibmir.wordpress.com/

pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: dynamic plpgsql command on a record type
Next
From: Richard Huxton
Date:
Subject: Re: problems maintaining boolean columns in a large table