Re: string reverse fucntion?

From: Vincenzo Romano <vincenzo(dot)romano(at)notorand(dot)it>
To: Shoaib Mir <shoaibmir(at)gmail(dot)com>
Cc: Richard Huxton <dev(at)archonet(dot)com>, AI Rumman <rummandba(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: string reverse fucntion?
Date: 2010-02-09 12:26:30
Message-ID: 3eff28921002090426v6915b3b0p4555940e0f21b406@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2010/2/9 Shoaib Mir <shoaibmir(at)gmail(dot)com>:
> On Tue, Feb 9, 2010 at 10:31 PM, Richard Huxton <dev(at)archonet(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Chris Barnes 2010-02-09 13:52:06 Warning when selecting column from pg_stat_user_tables.
Previous Message Richard Huxton 2010-02-09 11:45:01 Re: problems maintaining boolean columns in a large table