有一个临时表,我想用两次插入它:
CREATE OR REPLACE FUNCTION test1(user_id BIGINT) RETURNS BIGINT AS
$BODY$
BEGIN
DROP TABLE IF EXISTS temp_table1;
create temp table temp_table1
on commit drop
as select * from get_some_data($1); -- try to get the data for the 1st time
if not exists (select * temp_table1) then
select try_to_update_data($1); -- updates data, returns void
end if;
-- try to get the data again
select * into temp_table1 from get_some_data($1); -- error!
if not exists (select * from temp_table1) then
return 0;
end if;
--........ use temp_table1
它抛出错误:
ERROR: "temp_table1" is not a known variable
我该如何解决这个问题?
答案 0 :(得分:2)
写INSERT INTO temp_table1 SELECT get_some_data($1);
取代你所拥有的
select * into temp_table1 from get_some_data($1); -- error!
可能这对你有用。