Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,

We use copy command to copy data of one table to a file outside database.

Is it possible to copy data of one table to another table using command.

If yes can anyone please share the query.

Or is there any better approach like we can use pg_dump or something like that.

Appreciate your help.

Regards,
Mohit
Posted
Updated 7-Jul-15 19:48pm
v2

1 solution

If you are copying between two tables in the same database, you can do something like
SQL
INSERT INTO table2
(column_name(s))
SELECT column_name(s)
FROM table1;

Example:
SQL
INSERT INTO table2
SELECT * FROM table1;


Check this tutorial-
SQL INSERT INTO SELECT Statement[^]

Hope, it helps :)
 
Share this answer
 
Comments
Member 11802905 8-Jul-15 2:27am    
Thanks Suvendu for ur reply but I just want to know is it possible to copy data from one table to another using copy command.
Suvendu Shekhar Giri 8-Jul-15 2:41am    
I believe, "NO". As per the official documentation of PostgreSQL, COPY is used to copy data between a file and a table.
Check here PostgreSQL COPY
Member 11802905 8-Jul-15 5:28am    
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900