Re: "CREATE TEMPORARY TABLE" does not work in SQL language function?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David Johnston" <polobo(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: "CREATE TEMPORARY TABLE" does not work in SQL language function?
Date: 2013-01-31 19:52:16
Message-ID: 18705.1359661936@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"David Johnston" <polobo(at)yahoo(dot)com> writes:
> The only difference between the following two "CREATE FUNCTION" command is
> the language in which they are written.

The reason the SQL function doesn't work is that SQL functions parse and
analyze their whole bodies before beginning execution --- so "temptbl"
doesn't exist yet when the SELECT is analyzed. It's not about temp
tables as such, but rather that any DDL that affects the meaning of
later statements is problematic.

IIRC, there have been a few discussions about changing this behavior,
but nothing's been done, partly out of fear of breaking existing
applications.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Kevin Grittner 2013-01-31 20:17:53 Re: Pg & Tcl - is it dying out?
Previous Message Vincent Veyron 2013-01-31 19:30:04 Re: SQL sentence to insert where updated rows is zero...