Showing posts with label duplicate table. Show all posts
Showing posts with label duplicate table. Show all posts

Friday, January 24, 2020

PostgresSql option for creating table like another table


In MSSQL there is an easy, code-based, way to create a table with the same DDL and data as another table.
This is simply by running a query similar to this:



select * INTO "NEW TABLE" FROM "SOURCE TABLE"

I needed to do something similar in PostgreSQL and found this to be a nice way to recreate a table using another as a templet

CREATE TABLE TESTTABLE
AS
  SELECT *
  FROM "SOURCE TABLE"
  WHERE false;