Thaz
Thaz

Reputation: 65

Is it possible to create partitioned table with 'create table as' in PostgreSQL?

I am trying to create a partitioned table as follows:

create table archive.table1
   as table work1.table1 with no data
   partition by range (wk_date)

and I am getting the following error:

SQL Error [42601]: ERROR: syntax error at or near "partition"
  Position: 98

Upvotes: 0

Views: 2481

Answers (2)

Laurenz Albe
Laurenz Albe

Reputation: 246063

You can run the following, which is simpler and will work:

CREATE TABLE archive.table1 (LIKE work1.table1) PARTITION BY RANGE (wk_date);

Upvotes: 4

user330315
user330315

Reputation:

No, this is not possible.

You need to first create the partitioned table, then you need to create the partitions. Once that is done you can do an insert into partitioned_table select * from old_table

Upvotes: 0

Related Questions