string reverse fucntion?

Started by AI Rummanabout 16 years ago5 messagesgeneral
Jump to latest
#1AI Rumman
rummandba@gmail.com

I am using Postgresql 8.1.

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

Is there any function to do this?

#2Richard Huxton
dev@archonet.com
In reply to: AI Rumman (#1)
Re: string reverse fucntion?

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.

--
Richard Huxton
Archonet Ltd

#3Shoaib Mir
shoaibmir@gmail.com
In reply to: Richard Huxton (#2)
Re: string reverse fucntion?

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/

#4Vincenzo Romano
vincenzo.romano@notorand.it
In reply to: Shoaib Mir (#3)
Re: string reverse fucntion?

2010/2/9 Shoaib Mir <shoaibmir@gmail.com>:

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;

I think that Pavel's stuff is more interesting (and effective):

http://pgfoundry.org/projects/pstcollection/

--
Vincenzo Romano
NotOrAnd Information Technologies
NON QVIETIS MARIBVS NAVTA PERITVS

#5Pavel Stehule
pavel.stehule@gmail.com
In reply to: Vincenzo Romano (#4)
Re: string reverse fucntion?

Hello

I think that Pavel's stuff is more interesting (and effective):

http://pgfoundry.org/projects/pstcollection/

sorry, it is in orafce package (in pstcollection could be too (in future))

http://pgfoundry.org/projects/orafce

Regards
Pavel Stehule

Show quoted text

--
Vincenzo Romano
NotOrAnd Information Technologies
NON QVIETIS MARIBVS NAVTA PERITVS

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general