Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pWjjh-0004oL-EA for pgsql-general@arkaria.postgresql.org; Mon, 27 Feb 2023 20:04:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pWjjg-0006tv-7q for pgsql-general@arkaria.postgresql.org; Mon, 27 Feb 2023 20:04:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pWjjf-0006tl-Td for pgsql-general@lists.postgresql.org; Mon, 27 Feb 2023 20:04:35 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pWjjd-0004Zb-GM for pgsql-general@postgresql.org; Mon, 27 Feb 2023 20:04:35 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 31RK4VFh413923; Mon, 27 Feb 2023 15:04:31 -0500 From: Tom Lane To: nikhil raj cc: pgsql-general@postgresql.org Subject: Re: Tempory table is not getting created inside Function in postgres. In-reply-to: References: Comments: In-reply-to nikhil raj message dated "Tue, 28 Feb 2023 00:40:33 +0530" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <413921.1677528271.1@sss.pgh.pa.us> Date: Mon, 27 Feb 2023 15:04:31 -0500 Message-ID: <413922.1677528271@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk nikhil raj writes: > This is the Function I have created successfully but while executing it > throughs an error temp table doesn't exist. You won't be able to do it like that in a SQL-language function, because the whole function body is parsed and parse-analyzed in one go. So the later query referencing ROSTER_TABLE fails because it's parsed before the CREATE TABLE executes. (Improving that has been on the to-do list for a couple of decades, so don't hold your breath...) I suggest putting the whole thing, not just part of it, into plpgsql. regards, tom lane