Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 2CD849FB20B for ; Thu, 25 Jan 2007 11:06:15 -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 88999-02 for ; Thu, 25 Jan 2007 11:05:53 -0400 (AST) X-Greylist: delayed 00:26:12.221984 by SQLgrey-1.7.4 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 6819B9FB656 for ; Thu, 25 Jan 2007 11:06:05 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from pjetlic.mobart.hr (pjetlic.mobart.hr [80.80.51.10]) by svr4.postgresql.org (Postfix) with ESMTP id 9F4D85AFBAB for ; Thu, 25 Jan 2007 14:39:52 +0000 (GMT) Received: from localhost (localhost.localdomain [127.0.0.1]) by pjetlic.mobart.hr (Postfix) with ESMTP id 4FAC217F66 for ; Thu, 25 Jan 2007 15:39:25 +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 00436-02 for ; Thu, 25 Jan 2007 15:39:15 +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 A931617E0F for ; Thu, 25 Jan 2007 15:39:15 +0100 (CET) Subject: Using Temporary Tables in postgres functions From: Mario Splivalo Reply-To: mario.splivalo@mobart.hr To: pgsql-sql@postgresql.org Content-Type: text/plain Organization: Mob-Art d.o.o. Date: Thu, 25 Jan 2007 15:39:14 +0100 Message-Id: <1169735954.31872.38.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-Spam-Status: No, hits=1.385 tagged_above=0 required=5 tests=BAYES_50, SPF_SOFTFAIL, UPPERCASE_25_50 X-Spam-Level: * X-Archive-Number: 200701/118 X-Sequence-Number: 27270 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; When I try to execute above CREATE FUNCTION statement postgres gives me this: ERROR: relation "tmptbl" does not exist CONTEXT: SQL function "func1" If I rewrite func1() using 'plpgsq' I have no troubles creating temporary tables, I just need to use EXEC when referencing to those temporary tables (which is cumbersome, but there it is). Am I doing something wrong here, or there is no way of using temporary tables within 'sql' written functions? Mike