'INSERT INTO temp table not working in stored procedure [duplicate]

This script works fine when running on dbeaver, I can work with the new created temp table:

SELECT someField
INTO TEMP tmp_TableZZ 
FROM "_fdw_xxx".myTable;

But when inside a stored procedure, I got this error message:

SQL Error [42601]: ERROR: "temp" is not a known variable

Same code:

CREATE OR REPLACE procedure PopulateSomething() 
  LANGUAGE plpgsql
AS $procedure$
    DECLARE v_ReportDte date;
begin

--some code omitted

    SELECT someField
    INTO TEMP tmp_TableZZ 
    FROM "_fdw_xxx".myTable;

--some code omitted

end; $procedure$
;

Using TEMPORARY instead of TEMP got the same result.



Solution 1:[1]

well, I find out that SELECT INTO in SQL is different from SELECT INTO in pgsql. The former accepts TEMP as the parameter, the latter expects a variable to store some value.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 German EP