I'm trying to clone a table in sql with partial data but with all structure (index, etc). This is the code I'm trying to execute:
CREATE TABLE "new table" (LIKE "old table")
INSERT INTO "new table"
SELECT *
FROM "old table"
WHERE "date column" > ('now'::text::date - '1 year'::interval)
The error message says INSERT is wrong. When I execute only with LIKE it works, but when I try to input the data it doesn't.
Furthermore, the WHERE function is also correctly working.
Also, when I use CREATE TABLE "" AS it works and brings only the data without the structure. When I use LIKE it works and brings the structure without data. But, when I try to bring both data and structure it doesn't work and that is my question.