How to create a temporary table using select in PostgreSQL. For example, in SQL Select * into temp_tab from source_tab;
Select * into temp_tab from source_tab;
You can try using the Create Table command as follows:
CREATE TEMP TABLE mytable AS SELECT * from source_tab;
From the docs:
This command is functionally similar to SELECT INTO , but it is preferable because it is less likely to confuse SELECT INTO syntax with other uses. In addition, CREATE TABLE AS offers a superset of the functionality offered by SELECT INTO.The CREATE TABLE AS command allows the user to explicitly indicate whether to include the OID. If the presence of the OID is not explicitly specified, the default_with_oids configuration variable b.
This command is functionally similar to SELECT INTO , but it is preferable because it is less likely to confuse SELECT INTO syntax with other uses. In addition, CREATE TABLE AS offers a superset of the functionality offered by SELECT INTO.
The CREATE TABLE AS command allows the user to explicitly indicate whether to include the OID. If the presence of the OID is not explicitly specified, the default_with_oids configuration variable b.