預計現在將生成一個名爲waypoints
的表,並按照函數體進行操作。無法在Postgres函數中刪除臨時表:「正在由此會話中的活動查詢使用」
drop function if exists everything(waypoints);
create function everything(waypoints) RETURNS TABLE(node int, xy text[]) as $$
BEGIN
drop table if exists bbox;
create temporary table bbox(...);
insert into bbox
select ... from waypoints;
drop table if exists b_spaces;
create temporary table b_spaces(
...
);
insert into b_spaces
select ...
drop table if exists b_graph; -- Line the error flags.
create temporary table b_graph(
...
);
insert into b_graph
select ...
drop table if exists local_green;
create temporary table local_green(
...
);
insert into local_green
...
with aug_temp as (
select ...
)
insert into b_graph(source, target, cost) (
(select ... from aug_temp)
UNION
(select ... from aug_temp)
);
return query
with
results as (
select id1, ... from b_graph -- The relation being complained about.
),
pkg as (
select loc, ...
)
select id1, array_agg(loc)
from pkg
group by id1;
return;
END;
$$ LANGUAGE plpgsql;
這將返回cannot DROP TABLE b_graph because it is being used by active queries in this session
如何去糾正這個問題?
爲什麼使用臨時表?臨時表是否應該在函數外引用?另外:你的Postgres版本總是*必要的細節的一部分。 –
@ErwinBrandstetter因爲它們都是獲得我最終結果的中間體。我使用的是9.3,我將其添加到問題中。 – Louis93
另外,從CTE讀取和寫入的速度與從表讀取和寫入一樣快嗎?因爲當我提出意見時,每次訪問視圖時,視圖都會重新計算。 – Louis93