Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id C10759FA435 for ; Fri, 26 Jan 2007 06:46:42 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 69609-10 for ; Fri, 26 Jan 2007 06:46:35 -0400 (AST) X-Greylist: delayed 20:07:03.265647 by SQLgrey-1.7.4 Received: from pjetlic.mobart.hr (pjetlic.mobart.hr [80.80.51.10]) by postgresql.org (Postfix) with ESMTP id 850879FA30E for ; Fri, 26 Jan 2007 06:46:39 -0400 (AST) Received: from localhost (localhost.localdomain [127.0.0.1]) by pjetlic.mobart.hr (Postfix) with ESMTP id D1DBD17F66 for ; Fri, 26 Jan 2007 11:46:37 +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 01114-03-11 for ; Fri, 26 Jan 2007 11:46:37 +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 BE94B17AB5 for ; Fri, 26 Jan 2007 11:46:37 +0100 (CET) Subject: Re: Using Temporary Tables in postgres functions From: Mario Splivalo Reply-To: mario.splivalo@mobart.hr To: pgsql-sql@postgresql.org In-Reply-To: <20070125080212.M1153@megazone.bigpanda.com> References: <1169735954.31872.38.camel@localhost.localdomain> <20070125080212.M1153@megazone.bigpanda.com> Content-Type: text/plain Organization: Mob-Art d.o.o. Date: Fri, 26 Jan 2007 11:46:37 +0100 Message-Id: <1169808397.3045.13.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/134 X-Sequence-Number: 27286 On Thu, 2007-01-25 at 08:03 -0800, Stephan Szabo wrote: > On Thu, 25 Jan 2007, Mario Splivalo wrote: > > > When I try to use TEMPORARY TABLE within postgres functions (using 'sql' > > as a function language), I can't because postgres can't find that > > temporary table. Consider this example: > > > > CREATE FUNCTION func1() RETURNS SETOF v_messages_full AS $BODY$ > > CREATE TEMPORARY TABLE tmpTbl > > AS > > SELECT > > message_id > > FROM > > cached_messages > > WHERE > > billing_status = 2; > > > > > > UPDATE cached_messages SET billing_status = 1 WHERE message_id IN > > (SELECT message_id FROM tmpTbl); > > > > SELECT > > * > > FROM > > v_messages_full > > WHERE > > message_id IN (SELECT message_id FROM tmpTbl); > > $BODY$ LANGUAGE 'sql' VOLATILE SECURITY DEFINER; > > It seems like the sql function checker is unhappy with the above. Does it > actually work if you turn off the check_function_bodies configuration > variable, create the function and then call it? Yes, when I do 'set check_function_bodies to false;' then I can create the function but I'm unable to execute it: testdb1=# select * from func1(); ERROR: relation "tmptbl" does not exist CONTEXT: SQL function "func1" during startup Bummer. In the end I wrote the function using plpgsql. Now, is there any performance impact on using plpgsql instead of sql in simple scenarios as in func1() example? I guess there should be some, as minimas as it can be, but have no way of actualy knowing that. Mike