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: (view raw or whole thread)
Lists: pgsql-sql
create or replace function reverse_string(text) returns text as
    reversed_string text;
    incoming alias for $1;


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;

language plpgsql;

select * from reverse_string('Postgres');


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
Phone: 816-444-4422 ext. 6757
Fax: 913-498-1810

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-2015 The PostgreSQL Global Development Group