pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedEquivalent of Reverse() functions
3+ messages / 3 participants
[nested] [flat]
* Equivalent of Reverse() functions
@ 2003-11-27 06:50 Kumar <sgnerd@yahoo.com.sg>
2003-11-27 07:24 ` Re: Equivalent of Reverse() functions Joe Conway <mail@joeconway.com>
2003-11-29 17:51 ` Re: Equivalent of Reverse() functions greg@turnstep.com
0 siblings, 2 replies; 3+ messages in thread
From: Kumar @ 2003-11-27 06:50 UTC (permalink / raw)
To: pgsql-sql
Dear Friends,
I am migrating an SQL Server 2000 database to Postgres 7.3.4 running on RH Linux 7.2. While migrating I encounter SQL Server REVERSE( ) function, seems no such functions at Postgres.
Is there a equivalent function available at Postgres? Please shed some light
Regards
Kumar
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Equivalent of Reverse() functions
2003-11-27 06:50 Equivalent of Reverse() functions Kumar <sgnerd@yahoo.com.sg>
@ 2003-11-27 07:24 ` Joe Conway <mail@joeconway.com>
1 sibling, 0 replies; 3+ messages in thread
From: Joe Conway @ 2003-11-27 07:24 UTC (permalink / raw)
To: Kumar <sgnerd@yahoo.com.sg>; +Cc: pgsql-sql
Kumar wrote:
> I am migrating an SQL Server 2000 database to Postgres 7.3.4 running
> on RH Linux 7.2. While migrating I encounter SQL Server REVERSE( )
> function, seems no such functions at Postgres.
>
> Is there a equivalent function available at Postgres? Please shed
> some light
How about:
create or replace function reverse(text) returns text as '
return reverse($_[0]);
' language plperl;
regression=# select reverse('abcdef');
reverse
---------
fedcba
(1 row)
Joe
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Equivalent of Reverse() functions
2003-11-27 06:50 Equivalent of Reverse() functions Kumar <sgnerd@yahoo.com.sg>
@ 2003-11-29 17:51 ` greg@turnstep.com
1 sibling, 0 replies; 3+ messages in thread
From: greg@turnstep.com @ 2003-11-29 17:51 UTC (permalink / raw)
To: pgsql-sql; +Cc: sgnerd@yahoo.com.sg
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
> I am migrating an SQL Server 2000 database to Postgres 7.3.4 running
> on RH Linux 7.2. While migrating I encounter SQL Server REVERSE( )
> function, seems no such functions at Postgres.
>
> Is there a equivalent function available at Postgres? Please
> shed some light
No. If you have plperl installed, as somebody already posted, you can
take advantage of perl's built in reverse() function. Here is a
plpgsql version:
CREATE OR REPLACE FUNCTION reverse(TEXT) RETURNS TEXT AS '
DECLARE
original ALIAS FOR $1;
reversed TEXT := \'\';
onechar VARCHAR;
mypos INTEGER;
BEGIN
SELECT LENGTH(original) INTO mypos;
LOOP
EXIT WHEN mypos < 1;
SELECT substring(original FROM mypos FOR 1) INTO onechar;
reversed := reversed || onechar;
mypos := mypos -1;
END LOOP;
RETURN reversed;
END
' LANGUAGE plpgsql IMMUTABLE RETURNS NULL ON NULL INPUT;
pg=> SELECT reverse('A man, a plan, a canal, Panama');
reverse
- --------------------------------
amanap ,lanac a ,nalp a ,nam A
- --
Greg Sabino Mullane greg@turnstep.com
PGP Key: 0x14964AC8 200311291246
-----BEGIN PGP SIGNATURE-----
iD8DBQE/yNwwvJuQZxSWSsgRAnTyAJ9TqV0D3pV4Cv2b0VZfb8TxuvgxKgCeNBN+
OoFWwoD3omlLw+MUxcWZkT0=
=JtRf
-----END PGP SIGNATURE-----
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2003-11-29 17:51 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-11-27 06:50 Equivalent of Reverse() functions Kumar <sgnerd@yahoo.com.sg>
2003-11-27 07:24 ` Joe Conway <mail@joeconway.com>
2003-11-29 17:51 ` greg@turnstep.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