Thread: Postgresql 10 range partition

Postgresql 10 range partition

From
Garry Chen
Date:

HI All,

                I would like to create a range partition table but my question is when create the partitions can I use for values less then?  If LESS THEN is not passable what is my options?  Here is what I try to do.

 

CREATE TABLE measurement (

    city_id                     int not null,

    MONTH_SID         integer not null,

    peaktemp              int,

    unitsales                 int

) PARTITION BY RANGE (MONTH_SID);

CREATE TABLE measurement_y2010 PARTITION OF measurement

    FOR VALUES LESS THEN (201007)

NOTE: Any month_SID values less than 2010 July

CREATE TABLE measurement_y2011 PARTITION OF measurement

    FOR VALUES LESS THEN (201107)

NOTE: Any month_SID values between 2010 July  and 2011 June

….

Skip here

….

CREATE TABLE measurement_y2017 PARTITION OF measurement

    FOR VALUES LESS THEN (201707)

NOTE: Any month_SID values between 2016 July  and 2017 June

CREATE TABLE measurement_y2018 PARTITION OF measurement

    FOR VALUES LESS THEN (201807)

NOTE: Any month_SID values between 2017 July  and 2018 June

 

Thank you very much for your input,

Garry

 

Re: Postgresql 10 range partition

From
"David G. Johnston"
Date:
On Mon, Dec 18, 2017 at 9:43 AM, Garry Chen <gc92@cornell.edu> wrote:

HI All,

                I would like to create a range partition table but my question is when create the partitions can I use for values less then?  If LESS THEN is not passable what is my options? 


​Do you have a specific confusion regarding the docs on this matter?


Short answer, though, is that each partition exactly describes the data that belongs to it and does not require any other partition to exist nor changes with the introduction of new partitions.  Your "less than" construct fails this constraint.

You write:
"""
​ FOR VALUES LESS THEN (201807)

NOTE: Any month_SID values between 2017 July  and 2018 June
"""

Your English note and the pseudo-SQL you wrote do not agree - your English spec is the more useful one and is implemented using RANGE

David J.