Skip site navigation (1) Skip section navigation (2)

Re: Reverse String in sql or pgplsql

From: Bradley Miller <bmiller(at)nuvio(dot)com>
To: "Oisin Glynn" <me(at)oisinglynn(dot)com>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Reverse String in sql or pgplsql
Date: 2005-02-26 20:05:42
Message-ID: 3177ec80719b1221976bd55c5a9bde44@nuvio.com (view raw or flat)
Thread:
Lists: pgsql-sql
create or replace function reverse_string(text) returns text as
'
DECLARE
    reversed_string text;
    incoming alias for $1;

BEGIN

reversed_string = '''';

for i in reverse char_length(incoming)..1 loop

reversed_string = reversed_string || substring(incoming from i for 1);

end loop;

return reversed_string;



END'
language plpgsql;

select * from reverse_string('Postgres');

reverse_string
sergtsoP


On Feb 26, 2005, at 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
>
Bradley Miller
NUVIO CORPORATION
Phone: 816-444-4422 ext. 6757
Fax: 913-498-1810
http://www.nuvio.com
bmiller(at)nuvio(dot)com

In response to

pgsql-sql by date

Next:From: Joel FradkinDate: 2005-02-26 20:14:02
Subject: Re: diference in dates in minutes
Previous:From: Larry RosenmanDate: 2005-02-26 19:05:39
Subject: Re: Reverse String in sql or pgplsql

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group