Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 566149FB475; Mon, 16 Oct 2006 06:21:07 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 32844-04; Mon, 16 Oct 2006 06:21:02 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.logix-tt.com (mail.logix-tt.com [212.211.145.186]) by postgresql.org (Postfix) with ESMTP id 838B69FB3EE; Mon, 16 Oct 2006 06:21:02 -0300 (ADT) Received: from kingfisher.intern.logix-tt.com (84-72-188-217.dclient.hispeed.ch [84.72.188.217]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.logix-tt.com (Postfix) with ESMTP id 607E7657D3; Mon, 16 Oct 2006 11:23:28 +0200 (CEST) Received: from [127.0.0.1] (localhost [127.0.0.1]) by kingfisher.intern.logix-tt.com (Postfix) with ESMTP id D0B1618148BB6; Mon, 16 Oct 2006 11:20:40 +0200 (CEST) Message-ID: <45334EE8.2030800@logix-tt.com> Date: Mon, 16 Oct 2006 11:20:40 +0200 From: Markus Schaber Reply-To: pgsql-sql@postgresql.org Organization: Logical Tracking and Tracing International AG, Switzerland User-Agent: Thunderbird 1.5.0.7 (X11/20060927) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Cc: "Marc G. Fournier" Subject: Re: Recursive pl/pgsql function ... References: <7543.1160969254@sss.pgh.pa.us> In-Reply-To: <7543.1160969254@sss.pgh.pa.us> X-Enigmail-Version: 0.94.0.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.19 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200610/152 X-Sequence-Number: 26541 Hi, Marc, Hi, Tom, Tom Lane wrote: > "Marc G. Fournier" writes: >> More then one Record: >> # select get_next_billing_date(activated, 12) from company_details; >> ERROR: control reached end of function without RETURN >> CONTEXT: PL/pgSQL function "get_next_billing_date" > > Hm, what PG version is this? I couldn't duplicate that in HEAD, though > I did find out that a zero or negative payment_period makes it recurse > until "stack depth exceeded". And this is the reason why that function is a nice example where the recursive design approach is not necessary, and even hurts. A simple while-Loop will do the same, more efficient, and without any stack problems. Btw, it may even be possible to use an explicit formula to calculate this problem, but date and time calculations are always crazy. HTH, Markus -- Markus Schaber | Logical Tracking&Tracing International AG Dipl. Inf. | Software Development GIS Fight against software patents in Europe! www.ffii.org www.nosoftwarepatents.org