Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 76E831337BA3 for ; Tue, 8 Feb 2011 18:49:21 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 54449-04-3 for ; Tue, 8 Feb 2011 22:49:14 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id E9A031337BF7 for ; Tue, 8 Feb 2011 18:49:08 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p18Mn6GR010794; Tue, 8 Feb 2011 17:49:07 -0500 (EST) To: "Rodolfo Campero" cc: pgsql-bugs@postgresql.org Subject: Re: BUG #5872: Function call in SQL function executed only once In-reply-to: <201102082000.p18K0cWN037750@wwwmaster.postgresql.org> References: <201102082000.p18K0cWN037750@wwwmaster.postgresql.org> Comments: In-reply-to "Rodolfo Campero" message dated "Tue, 08 Feb 2011 20:00:38 +0000" Date: Tue, 08 Feb 2011 17:49:06 -0500 Message-ID: <10793.1297205346@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201102/77 X-Sequence-Number: 29349 "Rodolfo Campero" writes: > I stumbled upon a weird behavior of postgresql, I don't know if it's a bug > or not, but I find it counterintuitive: when then last statement of a SQL > function is a SELECT statement with calls another function, the call is > executed only once, regardless of the number of rows returned by the FROM > clause. Yeah, it stops as soon as it's got the one row needed for the function result. You might consider marking the function as returning SETOF if you want the final select executed to completion. regards, tom lane