This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In the previous post, I copied table data into another table.
In this post, I am creating a Copy of Table from another table of PostgreSQL.
For creating a duplicate table, we have two options like SELECT INTO and CREATE TABLE AS.
Check the below example:
Create a sample table with data:
1 2 3 4 5 6 |
CREATE TABLE tbl_A (ID INT); INSERT INTO tbl_A VALUES (1),(2),(3); |
Create tab_B as a duplicate table:
Using SELECT INTO:
1 |
SELECT * INTO tbl_B FROM tbl_A; |
Using CREATE TABLE AS:
1 2 |
CREATE TABLE tbl_B AS SELECT *FROM tbl_A; |
Check the result:
1 2 3 4 5 6 7 |
SELECT * FROM tbl_B; id -------- 1 2 3 |
Leave a Reply