I want to delete some rows from the table but I want my original table should not get altered. So for that I need to create duplicate/copy table and want to use alter or say delete command in the copied table.
Can you please provide me ways to copy a table in postgres.
Hi ravi
In Postgres SQL we can use the following commands in order to create a duplicate table.
# approach one with no conditions
CREATE TABLE new_table_name AS
TABLE existing_table_name
#approach 2 with conditions
# this code is for copying the `structure` of the table with no data.
CREATE TABLE new_table_name AS
TABLE existing_table_name
WITH NO DATA;
# Extracting and copying conditional data.
CREATE TABLE new_table_name AS
SELECT
*
FROM
existing_table_name
WHERE
condition;
Thanks Praneeth…This is quite useful…
1 Like