Re: Creating a partition table - Mailing list pgsql-admin

From Tom Lane
Subject Re: Creating a partition table
Date
Msg-id 98825.1604077633@sss.pgh.pa.us
Whole thread Raw
In response to Creating a partition table  (John Scalia <jayknowsunix@gmail.com>)
Responses Re: Creating a partition table
List pgsql-admin
John Scalia <jayknowsunix@gmail.com> writes:
> I have a PostgreSQL server version 11.3 that my devs are asking for some partitioned tables. I can’t seem to get the
syntaxcorrect though. My SQL code is: 

> CREATE TABLE schema.temp_table
> AS (SELECT * FROM schema.original_table)
> PARTITION BY LIST(attribute_name);

You can't create and populate a partitioned table in one command; you have
to create some partitions before you can load data into it.

I believe you could use CREATE TABLE temp_table (LIKE original_table)
PARTITION BY LIST(attribute_name) to avoid manually repeating the
column list.  Check the docs to see which other LIKE options you want
to use.

            regards, tom lane



pgsql-admin by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: Creating a partition table
Next
From: John Scalia
Date:
Subject: Re: Creating a partition table