From: Andrew Hammond <drew@xyzzy.dhs.org>
To: pgsql-sql@postgresql.org
Subject: simple recursive function in plpgsql fails
Date: Thu, 13 Jun 2002 19:39:39 -0400
Message-ID: <3D092D3B.3070308@xyzzy.dhs.org> (raw)
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@xyzzy.dhs.org <mailto:drew@xyzzy.dhs.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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: drew@xyzzy.dhs.org
Subject: Re: simple recursive function in plpgsql fails
In-Reply-To: <3D092D3B.3070308@xyzzy.dhs.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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