Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 26AC19FB651 for ; Thu, 25 Jan 2007 12:03:59 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 82953-06 for ; Thu, 25 Jan 2007 12:03:52 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by postgresql.org (Postfix) with ESMTP id E8CEB9FB654 for ; Thu, 25 Jan 2007 12:03:51 -0400 (AST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 4BAAF35348; Thu, 25 Jan 2007 08:03:51 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 4A22035290; Thu, 25 Jan 2007 08:03:51 -0800 (PST) Date: Thu, 25 Jan 2007 08:03:51 -0800 (PST) From: Stephan Szabo To: Mario Splivalo Cc: pgsql-sql@postgresql.org Subject: Re: Using Temporary Tables in postgres functions In-Reply-To: <1169735954.31872.38.camel@localhost.localdomain> Message-ID: <20070125080212.M1153@megazone.bigpanda.com> References: <1169735954.31872.38.camel@localhost.localdomain> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/120 X-Sequence-Number: 27272 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?