pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
simple recursive function in plpgsql fails
2+ messages / 2 participants
[nested] [flat]

* simple recursive function in plpgsql fails
@ 2002-06-13 23:39 Andrew Hammond <drew@xyzzy.dhs.org>
  2002-06-14 05:02 ` Re: simple recursive function in plpgsql fails Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: Andrew Hammond @ 2002-06-13 23:39 UTC (permalink / raw)
  To: 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@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





^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: simple recursive function in plpgsql fails
  2002-06-13 23:39 simple recursive function in plpgsql fails Andrew Hammond <drew@xyzzy.dhs.org>
@ 2002-06-14 05:02 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2002-06-14 05:02 UTC (permalink / raw)
  To: Andrew Hammond <drew@xyzzy.dhs.org>; +Cc: pgsql-sql

Andrew Hammond <drew@xyzzy.dhs.org> writes:
> [ problems with a recursive plpgsql function ]

Yeah, there are some known bugs there :-(.  AFAICS this cannot be
fixed properly until we get around to doing the querytree restructuring
that I keep ranting about --- in particular, making a clean distinction
between plan tree and execution state.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2002-06-14 05:02 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-06-13 23:39 simple recursive function in plpgsql fails Andrew Hammond <drew@xyzzy.dhs.org>
2002-06-14 05:02 ` Tom Lane <tgl@sss.pgh.pa.us>

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