-----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;
SELECTsubstring(original FROM mypos FOR 1) INTO onechar; reversed := reversed || onechar; mypos := mypos -1;
ENDLOOP; 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-----