Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hMRXx-0006Tu-FM for pgsql-general@arkaria.postgresql.org; Fri, 03 May 2019 06:19:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hMRXw-0002lw-1q for pgsql-general@arkaria.postgresql.org; Fri, 03 May 2019 06:19:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hMRXv-0002lp-OF for pgsql-general@lists.postgresql.org; Fri, 03 May 2019 06:19:47 +0000 Received: from mx1.mailbox.org ([80.241.60.212]) by magus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hMRXs-0002YY-NN for pgsql-general@lists.postgresql.org; Fri, 03 May 2019 06:19:47 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx1.mailbox.org (Postfix) with ESMTPS id 3CC574D9EE; Fri, 3 May 2019 08:19:43 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter05.heinlein-hosting.de (spamfilter05.heinlein-hosting.de [80.241.56.123]) (amavisd-new, port 10030) with ESMTP id XrbgN8ZcK5L4; Fri, 3 May 2019 08:19:22 +0200 (CEST) Message-ID: <556ca13c06e96fe165ee03d297f42bb405807bed.camel@cybertec.at> Subject: Re: Migrating an application with Oracle temporary tables From: Laurenz Albe To: Mark Zellers , "pgsql-general@lists.postgresql.org" Date: Fri, 03 May 2019 08:19:21 +0200 In-Reply-To: References: <9abb9aaf36ac04389f67b8d8e0ea6840f0f69f1e.camel@cybertec.at> Organization: Cybertec Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, 2019-05-02 at 16:55 +0000, Mark Zellers wrote: > I thought I needed the prototype table to be able to define functions and procedures that refer to the temporary table but do not create it. > > Perhaps my assumption that I need the table to exist (whether as a temporary table or as a permanent table) in > order to define the function/procedure is incorrect. I'll take a look at that. You don't need the table to exist at function definition time. The following works just fine, even if the table does not exist: CREATE FUNCTION f() RETURNS void LANGUAGE plpgsql AS $$BEGIN PERFORM * FROM notexists; END;$$; This is because functions are not parsed when they are defined. > I did find a scenario where this approach does run into trouble. That is, if the function/procedure is executed > against the permanent table and then you go to run it against a temporary table. In that case, I do get the > wrong answer, and I haven't yet figured out how to reset that without dropping the procedure and re-defining it. > For my purposes, that is "good enough" -- I can promise not to run such procedures against the temporary table. Yes, that would cause a problem. The SQL statement "DISCARD PLANS" should fix the problem. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com