简体   繁体   English

在MonetDB中的函数内删除本地临时表

[英]Drop a local temporary table within a function in MonetDB

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 : 我有一堆用户定义的函数f_i ,它们创建,填充并使用具有相同名称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? 我的第一个问题是: Does create local temporary table x一个表,该表在声明了该函数的函数完成执行后立即被处置/删除? 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. 我以为是这种情况,但是我怀疑,因为我们遇到了各种并发问题,这些问题指向res表没有从内存中正确清除。

This takes me to the second question: How do I drop a temporary table if such table exists? 这将我带到第二个问题:如果存在临时表,如何删除该临时表? The reason for this is to prevent table create exceptions (which we are currently running into). 这样做的原因是为了防止table create异常(我们当前正在运行)。 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. 如您所见,我想在哪里明确删除本地临时表res如果存在)。 If I leave the local temporary markers in the drop statement, MonetDB complains that it found unexpected LOCAL or TEMPORARY tokens. 如果我在drop语句中保留local temporary标记,MonetDB会抱怨它发现了意外的LOCALTEMPORARY标记。 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. 将删除默认函数模式中具有该名称的任何表。

Any help and hints are well appreciated! 任何帮助和提示,我们将不胜感激!

尝试跟随?

IF OBJECT_ID('tempdb..#Temp') IS NOT NULL   DROP TABLE #Temp;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM