Re: Creating a partition table

From: John Scalia <jayknowsunix(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-admin <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Creating a partition table
Date: 2020-10-30 17:40:21
Message-ID: 72BCF3AA-1931-4BD9-A00D-497B3C2553E2@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Well, originally my code had a WITH NO DATA before the PARTITION BY clause, but that was error in as well, but thinking that I would just get structure of the table that way, the error didn’t make any sense.

I’ll try Laurenz’s code example and see what happens.

Sent from my iPad

> On Oct 30, 2020, at 1:07 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> John Scalia <jayknowsunix(at)gmail(dot)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 syntax correct 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

Browse pgsql-admin by date

  From Date Subject
Next Message John Scalia 2020-10-30 17:48:53 Re: Creating a partition table
Previous Message Tom Lane 2020-10-30 17:07:13 Re: Creating a partition table