skip to Main Content

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?

2

Answers


  1. its may be work :

    INSERT INTO tTemp
    select  tt.id, tt.name
    from    test.TestTable tt
    
    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search