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