X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 98BB29FA1B0 for ; Sun, 7 May 2006 20:33:54 -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 55266-01 for ; Sun, 7 May 2006 20:33:49 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mx3.surnet.cl (mx3.surnet.cl [216.155.73.182]) by postgresql.org (Postfix) with ESMTP id 6FE189F9AFD for ; Sun, 7 May 2006 20:33:48 -0300 (ADT) Received: from unknown (HELO cluster.surnet.cl) ([216.155.73.165]) by mx3.surnet.cl with ESMTP; 07 May 2006 19:33:45 -0400 X-IronPort-AV: i="4.04,172,1144036800"; d="scan'208"; a="11893180:sNHT18370300" Received: from alvh.no-ip.org (201.220.122.210) by cluster.surnet.cl (7.0.043) (authenticated as alvherre@surnet.cl) id 443B7DDC003A387E; Sun, 7 May 2006 19:33:44 -0400 Received: by alvh.no-ip.org (Postfix, from userid 1000) id 0C677C31DEB; Sun, 7 May 2006 19:33:44 -0400 (CLT) Date: Sun, 7 May 2006 19:33:43 -0400 From: Alvaro Herrera To: Jorge Godoy Cc: pgsql-sql@postgresql.org Subject: Re: Creating nested functions with plpgsql Message-ID: <20060507233343.GC31301@surnet.cl> Mail-Followup-To: Jorge Godoy , pgsql-sql@postgresql.org References: <200605021414.49661.jgodoy@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200605021414.49661.jgodoy@gmail.com> User-Agent: Mutt/1.5.11+cvs20060403 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/80 X-Sequence-Number: 25111 Jorge Godoy wrote: > I have some real case examples where this could be useful, if it is needed. > I haven't pasted them here because the smallest one has 176 LOC, after > refactoring with nested functions. > > If it is not possible, are there any plans to allow this kind of thing? > (Even with a different syntax it would be good to have it.) We don't support nested functions at present, but you can create a separate function and invoke it as you would call any external function. This is arguably better, because you may then use inner_function in any "outer function", not just the current one. Something like: CREATE FUNCTION inner_function(OUT output_day DATE) AS $_$ DECLARE output_day DATE; BEGIN -- do something to calculate output_day RETURN output_day; END $_$; CREATE FUNCTION outer_function(param1 DATE) RETURNS date AS $$ DECLARE output_day DATE; BEGIN; output_day = SELECT inner_function(params_to_create_date); -- do something in main function that uses inner function several -- times. END; $$ language plpgsql; -- Alvaro Herrera http://www.CommandPrompt.com/ The PostgreSQL Company - Command Prompt, Inc.