36

How to create temporary table using select into in PostgreSQL. For example in SQL Select * into temp_tab from source_tab;

1

1 Answer 1

74

You can try to use Create Table As command like this:

CREATE TEMP TABLE mytable AS
SELECT * from source_tab;

From the docs:

This command is functionally similar to SELECT INTO, but it is preferred since it is less likely to be confused with other uses of the SELECT INTO syntax. Furthermore, CREATE TABLE AS offers a superset of the functionality offered by SELECT INTO.

The CREATE TABLE AS command allows the user to explicitly specify whether OIDs should be included. If the presence of OIDs is not explicitly specified, the default_with_oids configuration variable is used.

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

1 Comment

Thanks for your quick response...should i use without create temp ....i.e in your example...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.