Temp Table In SQL Function

Started by cnover 24 years ago1 messagesgeneral
Jump to latest
#1cn
cnliou@eurosport.com

Hello!

I am trying to create a sql function that returns 2
values using temporary table as the "media":

database1=# CREATE FUNCTION SaveNumeric(int2,int2)
RETURNS INTEGER AS '
database1'# CREATE TEMP TABLE mytemp(a int2,b int2);
database1'# INSERT INTO mytemp VALUES ($1+1,$2+100);
database1'# SELECT 1;
database1'# ' LANGUAGE 'sql';
ERROR: Relation 'mytemp' does not exist

But below seems to work:

database1=# CREATE FUNCTION Drop2Numeric() RETURNS
INTEGER AS '
database1'# DROP TABLE mytemp;
database1'# SELECT 1;
database1'# ' LANGUAGE 'sql';
CREATE

Why the creation of SaveNumeric(int2,int2) fails
while the creation of Drop2Numeric() succeeds?

Regards,

CN

--------------------------------------------------------
You too can have your own email address from Eurosport.
http://www.eurosport.com