Answers inserted below


On 20-03-17 23:27, Luis Larios wrote:

Hi, all,

 

Consider the following scenario.  I have a bunch of user defined functions, f_i, that create, populate, and use a local temporary table with the same name “res”:

 

create function f_i()

returns table( … )

begin

       # Result stats table.

       create local temporary table res(

             param1 int,

             param2 int

       );

   

       /* Populate res */

       /* Use res in some queries */

      

return table(

       /* Query involving res */

       );

end;

 

My first question is: Does “create local temporary table x” create a table that is disposed/dropped as soon as the function where it was declared finishes execution?

No. The table remains till the end of the user session.

  I assumed this was the case, but I’m now skeptical as we are running into all sorts of concurrency issues that point to the “res” table not being cleared out properly from memory.

 

This takes me to the second question:  How do I drop a temporary table if such table exists?

Use DROP TABLE "tmp".res;

  The reason for this is to prevent “table create” exceptions (which we are currently running into).  I’d like to achieve something along these lines:

 

create function f_i()

returns table( … )

begin

       # Drop local temporary table if such table exists.

       drop local temporary table res;         <-------- How do I do this in MonetDB?

 

       # Result stats table.

       create local temporary table res(

             param1 int,

             param2 int

       );

   

       /* Populate res */

       /* Use res in some queries */

      

return table(

       /* Query involving res */

       );

end;

 

Where, as you can see, I want to explicitly drop the local temporary table “res” if such exists.  If I leave the “local temporary” markers in the drop statement, MonetDB complains that it found unexpected “LOCAL” or “TEMPORARY”.  I wouldn’t like to remove these markers because a statement like:

 

drop table res;

 

will drop any table in the default function schema with that name.

All the temporary tables are stored in schema "tmp". To list them use:
select (select name from sys.schemas s where s.id = t.schema_id) as sch_nm, t.* from sys.tables t where temporary = 1 or type in (20, 30);

To drop a temporary table use the full qualified name such as: DROP TABLE "tmp".res;

 

Any help and hints are well appreciated!

 

Thanks for the help in advance

 

~ Luis Angel

 

_______________________________________________
users-list mailing list
users-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/users-list