Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 8395B9FA435 for ; Fri, 26 Jan 2007 06:51:56 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 10728-03 for ; Fri, 26 Jan 2007 06:51:49 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from pjetlic.mobart.hr (pjetlic.mobart.hr [80.80.51.10]) by postgresql.org (Postfix) with ESMTP id 54DD59FA30E for ; Fri, 26 Jan 2007 06:51:53 -0400 (AST) Received: from localhost (localhost.localdomain [127.0.0.1]) by pjetlic.mobart.hr (Postfix) with ESMTP id E556C17F66; Fri, 26 Jan 2007 11:51:51 +0100 (CET) Received: from pjetlic.mobart.hr ([127.0.0.1]) by localhost (pjetlic [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 11152-09; Fri, 26 Jan 2007 11:51:45 +0100 (CET) Received: from mike.mobart.hr (mike.mobart.hr [192.168.10.94]) (using SSLv3 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by pjetlic.mobart.hr (Postfix) with ESMTP id 9F22217AB5; Fri, 26 Jan 2007 11:51:45 +0100 (CET) Subject: Re: Using Temporary Tables in postgres functions From: Mario Splivalo Reply-To: mario.splivalo@mobart.hr To: Tom Lane Cc: pgsql-sql@postgresql.org In-Reply-To: <20030.1169741373@sss.pgh.pa.us> References: <1169735954.31872.38.camel@localhost.localdomain> <20030.1169741373@sss.pgh.pa.us> Content-Type: text/plain Organization: Mob-Art d.o.o. Date: Fri, 26 Jan 2007 11:51:45 +0100 Message-Id: <1169808705.3045.21.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.6.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by OpenSource AV+AS Mail Server X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/136 X-Sequence-Number: 27288 On Thu, 2007-01-25 at 11:09 -0500, Tom Lane wrote: > Mario Splivalo writes: > > Am I doing something wrong here, or there is no way of using temporary > > tables within 'sql' written functions? > > I believe the problem is that for a SQL function we parse the whole > function body before executing any of it. So you'd need to split this > into two separate functions. Having two function complicates, a bit, interface between applicaation and the database. But, then again, If I split it in two functions, then one with the UPDATE still can't find temp table referenced in other function, right? I have no problem writing func1() example in plpgsql, it just seemed to me that using sql instead of plpgsql (when I actually can use sql) gives me a little performance improvement. Mike