I am creating a temp table, and am fetching data from multiple tables and inserting data into it. When I try to get the data back from the table I get an error:
[42601] ERROR: query has no destination for result data Hint: If you want to discard the results of a SELECT, use PERFORM instead.
do
$$
DECLARE
sampleproductId varchar;
productIds text[] := array [
'abc1',
'abc2'
];
tId varchar;
DECLARE result jsonb;
DECLARE resultS jsonb[];
begin
CREATE TEMP TABLE IF NOT EXISTS product_temp_mapping
(
accountid int,
productUID varchar,
sampleproductId text
);
FOREACH sampleproductId IN ARRAY productIds
LOOP
tId := (select id
from product.product
where uid = sampleproductId);
INSERT into product_temp_mapping (accountid, productUID, sampleproductId)
select accountid, tId, sampleproductId
from product.accountproductmap
where productId = cast(tId as int);
END LOOP;
select * from product_temp_mapping;
end ;
$$;
Is this the right way to do it? This is the first time I am doing something with a temp table.