"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