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 );