Re: Restriction on table partition expressions

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: James Vanns <jvanns(at)ilm(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Restriction on table partition expressions
Date: 2022-08-25 15:25:14
Message-ID: CAApHDvpT9W0TbE=Kr_KaX4k_rHrKR89tLEZf3z=rU4=scFD0jA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, 26 Aug 2022 at 03:08, James Vanns <jvanns(at)ilm(dot)com> wrote:
> CREATE TABLE foobar(
> id BIGINT NOT NULL PRIMARY KEY,
> baz VARCHAR NULL DEFAULT NULL
> ) PARTITION BY HASH(my_func(id));
>
> Error: primary key constraints cannot be used when partition keys
> include expressions.

> I couldn't find much, if anything, about using expressions in table
> partitions let alone describing the restriction. Can anyone enlighten
> me? Or point me to what I've missed! Also, is there a chance that this
> limitation will be relaxed in the future?

This is mentioned in [1]:

"Unique constraints (and hence primary keys) on partitioned tables
must include all the partition key columns. This limitation exists
because the individual indexes making up the constraint can only
directly enforce uniqueness within their own partitions; therefore,
the partition structure itself must guarantee that there are not
duplicates in different partitions."

Maybe that could be more clear and mention that all the primary key
columns must be present and not be part of a function call or
expression.

David

[1] https://www.postgresql.org/docs/13/ddl-partitioning.html

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David Rowley 2022-08-25 15:31:53 Re: Restriction on table partition expressions
Previous Message James Vanns 2022-08-25 15:08:24 Restriction on table partition expressions