I've got a temp table which I want to use twice to insert into it:
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
It trows the error:
ERROR: "temp_table1" is not a known variable
How do I solve this?
write INSERT INTO temp_table1 SELECT get_some_data($1);
in place of what you had
select * into temp_table1 from get_some_data($1); -- error!
May be this will work for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With