pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bradley Miller <bmiller@nuvio.com>
To: Oisin Glynn <me@oisinglynn.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Reverse String in sql or pgplsql
Date: Sat, 26 Feb 2005 14:05:42 -0600
Message-ID: <3177ec80719b1221976bd55c5a9bde44@nuvio.com> (raw)
In-Reply-To: <006f01c51c2c$54fb6ef0$a974fea9@homisco.local>
References: <200502241717.14648.aarni@kymi.com>
	<1109424259.10941.6.camel@localhost.localdomain>
	<006f01c51c2c$54fb6ef0$a974fea9@homisco.local>

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@nuvio.com

view thread (3+ messages)

Message-ID: <3177ec80719b1221976bd55c5a9bde44@nuvio.com>
Permalink:  ../3177ec80719b1221976bd55c5a9bde44@nuvio.com/
Also on:    postgresql.org/message-id/3177ec80719b1221976bd55c5a9bde44@nuvio.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: bmiller@nuvio.com, me@oisinglynn.com
  Subject: Re: Reverse String in sql or pgplsql
  In-Reply-To: <3177ec80719b1221976bd55c5a9bde44@nuvio.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox