Home Databases pgSql How to copy data from one table to another using pgsql
 
 
 

How to copy data from one table to another using pgsql

PDF Print E-mail

If you need to copy data from one table (table_a) into another table (table_b) using pgsql.

There are 2 methods on how to do this.

Method 1

NOTE: If you are using this method table_b should not yet exist.

If you want an exact duplicate without indexing or relying on objects use this.

SELECT * INTO table_b FROM table_a

Method 2

NOTE: This method will work if table_b already exist.

This method uses a subselect inside the INSERT statement

INSERT INTO table_b
(
       SELECT        
         *
       FROM
         table_a
      WHERE condition
);  

+/-
+/- Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
Security Please input the anti-spam code that you can read in the image.
 

Go Daddy $7.49 .com Sale!