When I using query to select values to temp table like this:
drop table if exists tTemp;
select tt.id, tt.name
into tTemp
from test.TestTable tt
It's work great. But when I using this construction in function I have this error:
[42601] ERROR: "tTemp" is not a known variableq
Why this construction don't work in function?
CodePudding user response:
Use the standard compliant CRATE TABLE AS SELECT instead of the discouraged select ... into to avoid the ambiguity between storing the result of a query into a PL/pgSQL variable and creating a new table:
drop table if exists tTemp;
create table ttemp
as
select tt.id, tt.name
from test.TestTable tt
This is one of the reasons the manual recommends to use CREATE TABLE AS instead of select into
CodePudding user response:
its may be work :
INSERT INTO tTemp
select tt.id, tt.name
from test.TestTable tt