0

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?

1
  • into has a different meaning in PL/pgSQL code. See the documentation Commented Nov 22, 2022 at 8:00

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

its may be work :

INSERT INTO tTemp
select  tt.id, tt.name
from    test.TestTable tt

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.