Re: Tempory table is not getting created inside Function in postgres. - Mailing list pgsql-general

From nikhil raj
Subject Re: Tempory table is not getting created inside Function in postgres.
Date
Msg-id CAG1ps1ymquz0VBReyqcx2Gh8Nhjvdjg+Wbr-q-NT+Et6H_MZaA@mail.gmail.com
Whole thread Raw
In response to Re: Tempory table is not getting created inside Function in postgres.  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Tempory table is not getting created inside Function in postgres.  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-general
Hi Tom,

The same query  is executed outside the function its working properly  means just the qurey from drop temp table to insert but when i keep the query inside a function its through me the error an after temp ra how creation only i am using the select statment still its not exectuing the create  statment or not storing the temp table.

On Tue, 28 Feb, 2023, 1:34 am Tom Lane, <tgl@sss.pgh.pa.us> wrote:
nikhil raj <nikhilraj474@gmail.com> 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

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Tempory table is not getting created inside Function in postgres.
Next
From: "David G. Johnston"
Date:
Subject: Re: Tempory table is not getting created inside Function in postgres.