From: | Andrew Hammond <drew(at)xyzzy(dot)dhs(dot)org> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | simple recursive function in plpgsql fails |
Date: | 2002-06-13 23:39:39 |
Message-ID: | 3D092D3B.3070308@xyzzy.dhs.org |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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 drew(at)xyzzy(dot)dhs(dot)org <mailto:drew(at)xyzzy(dot)dhs(dot)org>
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
From | Date | Subject | |
---|---|---|---|
Next Message | joo | 2002-06-14 02:03:58 | Re: join question - requesting for a simple C program where it can INSERT data into database as reference |
Previous Message | Dmitri Colebatch | 2002-06-13 22:38:39 | Re: join question - three tables, two with foreign keys to the first |