0

I was wondering if there is a command to clone a table in PostgreSQL. By cloning I mean with the same schema, so that it already identifies the primary key, foreign keys (if applicable), etc.

Thanks

Mangostino
  • 157
  • 1
  • 6
  • 1
    Does this answer your question? [Copy table structure into new table](https://stackoverflow.com/questions/1220453/copy-table-structure-into-new-table) – U880D Oct 12 '21 at 12:19

1 Answers1

0

I believe the answer is here, in the deep cloning part of the article

CREATE TABLE new_table LIKE original_table;
INSERT INTO new_table SELECT * FROM original_table;

https://towardsdatascience.com/how-to-clone-tables-in-sql-dd29586ec89c

Mangostino
  • 157
  • 1
  • 6