pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedReverse String in sql or pgplsql
3+ messages / 3 participants
[nested] [flat]
* Reverse String in sql or pgplsql
@ 2005-02-26 17:55 Oisin Glynn <me@oisinglynn.com>
2005-02-26 19:05 ` Re: Reverse String in sql or pgplsql Larry Rosenman <ler@lerctr.org>
2005-02-26 20:05 ` Re: Reverse String in sql or pgplsql Bradley Miller <bmiller@nuvio.com>
0 siblings, 2 replies; 3+ messages in thread
From: Oisin Glynn @ 2005-02-26 17:55 UTC (permalink / raw)
To: pgsql-sql
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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Reverse String in sql or pgplsql
2005-02-26 17:55 Reverse String in sql or pgplsql Oisin Glynn <me@oisinglynn.com>
@ 2005-02-26 19:05 ` Larry Rosenman <ler@lerctr.org>
1 sibling, 0 replies; 3+ messages in thread
From: Larry Rosenman @ 2005-02-26 19:05 UTC (permalink / raw)
To: Oisin Glynn <me@oisinglynn.com>; +Cc: pgsql-sql
On Saturday 26 February 2005 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
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;
from a posting a while back.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Reverse String in sql or pgplsql
2005-02-26 17:55 Reverse String in sql or pgplsql Oisin Glynn <me@oisinglynn.com>
@ 2005-02-26 20:05 ` Bradley Miller <bmiller@nuvio.com>
1 sibling, 0 replies; 3+ messages in thread
From: Bradley Miller @ 2005-02-26 20:05 UTC (permalink / raw)
To: Oisin Glynn <me@oisinglynn.com>; +Cc: 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@nuvio.com
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2005-02-26 20:05 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-02-26 17:55 Reverse String in sql or pgplsql Oisin Glynn <me@oisinglynn.com>
2005-02-26 19:05 ` Larry Rosenman <ler@lerctr.org>
2005-02-26 20:05 ` Bradley Miller <bmiller@nuvio.com>
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