How to create temporary table using select into in PostgreSQL. For example in SQL Select * into temp_tab from source_tab;
            Asked
            
        
        
            Active
            
        
            Viewed 5.1k times
        
    32
            
            
         
    
    
        user1766169
        
- 1,932
- 3
- 22
- 44
 
    
    
        Parthasarathi 
        
- 323
- 1
- 3
- 7
- 
                    2Your question have answer here : http://stackoverflow.com/questions/15691243/creating-temporary-tables-in-sql – Madhusudan Apr 30 '15 at 10:25
1 Answers
65
            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.
 
    
    
        Rahul Tripathi
        
- 168,305
- 31
- 280
- 331
- 
                    Thanks for your quick response...should i use without create temp ....i.e in your example... – Parthasarathi Apr 30 '15 at 10:11