ians=# SELECT version();
                            version
---------------------------------------------------------------
 PostgreSQL 7.1.3 on i686-pc-linux-gnu, compiled by GCC 2.95.4

My goal is to find the last occurance of a pattern in a string.  As a 
helper function, I wrote this:

DROP FUNCTION reverse(text);
CREATE FUNCTION reverse(text) RETURNS text AS
'DECLARE str ALIAS FOR $1;
BEGIN   IF length(str) > 1 THEN
                RETURN reverse(substr(str, 2)) || substr(str, 1, 1);
        ELSE
                RETURN str;
        END IF;
END;' LANGUAGE 'plpgsql'

ians=# SELECT reverse('q');
 reverse
---------
 q
(1 row)

ians=# SELECT reverse('qw');
 reverse
---------
 wq
(1 row)

ians=# SELECT reverse('qwe');
 reverse
---------
 ewq
(1 row)

ians=# SELECT reverse('qwer');
 reverse
---------
 rerq
(1 row)

Ooops...

 
------------------------------------------------------------------------
Andrew G. Hammond [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> 
http://xyzzy.dhs.org/~drew/ <http://xyzzy.dhs.org/%7Edrew/>
56 2A 54 EF 19 C0 3B 43 72 69 5B E3 69 5B A1 1F 613-389-5481
5CD3 62B0 254B DEB1 86E0 8959 093E F70A B457 84B1



---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])

Reply via email to