From 47c9edf3e46080d4bfb7d2a2908016c9039ee20f Mon Sep 17 00:00:00 2001 From: amit Date: Thu, 26 Jan 2017 18:57:55 +0900 Subject: [PATCH 1/3] Improve CREATE TABLE documentation of partitioning --- doc/src/sgml/ref/create_table.sgml | 103 ++++++++++++++++++++++++++++++++++--- 1 file changed, 96 insertions(+), 7 deletions(-) diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_table.sgml index 58f8bf6d6a..5596250aef 100644 --- a/doc/src/sgml/ref/create_table.sgml +++ b/doc/src/sgml/ref/create_table.sgml @@ -85,8 +85,8 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI and partition_bound_spec is: -{ IN ( expression [, ...] ) | - FROM ( { expression | UNBOUNDED } [, ...] ) TO ( { expression | UNBOUNDED } [, ...] ) } +{ IN ( { bound_literal | NULL } [, ...] ) | + FROM ( { bound_literal | UNBOUNDED } [, ...] ) TO ( { bound_literal | UNBOUNDED } [, ...] ) } index_parameters in UNIQUE, PRIMARY KEY, and EXCLUDE constraints are: @@ -261,6 +261,44 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI any existing partition of that parent. + + + Each of the values specified in the partition bound specification is + a literal, NULL, or UNBOUNDED. + A literal is either a numeric constant or a string constant that can be + automatically coerced to the corresponding partition key column's type. + + + + When creating a range partition, the lower bound specified with + FROM is an inclusive bound, whereas the upper bound + specified with TO is an exclusive bound. That is, + the values specified in the FROM list are accepted + values of the corresponding partition key columns in a given partition, + whereas those in the TO list are not. To be precise, + this applies only to the first of the partition key columns for which + the corresponding values in the FROM and + TO lists are not equal. All rows in a given + partition contain the same values for all preceding columns, equal to + those specified in FROM and TO + lists. On the other hand, any subsequent columns are insignificant + as far as implicit partition constraint is concerned. + + Specifying UNBOUNDED in FROM + signifies -infinity as the lower bound of the + corresponding column, whereas it signifies +infinity + as the upper bound when specified in TO. + + + + When creating a list partition, NULL can be specified + to signify that the partition allows the partition key column to be null. + However, there cannot be more than one such list partitions for a given + parent table. NULL cannot specified for range + partitions. + + + A partition cannot have columns other than those inherited from the parent. That includes the oid column, which can be @@ -386,11 +424,12 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI partitioned table. The parenthesized list of columns or expressions forms the partition key for the table. When using range partitioning, the partition key can - include multiple columns or expressions, but for list partitioning, the - partition key must consist of a single column or expression. If no - btree operator class is specified when creating a partitioned table, - the default btree operator class for the datatype will be used. If - there is none, an error will be reported. + include multiple columns or expressions (up to 32, but this limit can + altered when building PostgreSQL.), but for + list partitioning, the partition key must consist of a single column or + expression. If no btree operator class is specified when creating a + partitioned table, the default btree operator class for the datatype will + be used. If there is none, an error will be reported. @@ -1485,6 +1524,16 @@ CREATE TABLE measurement ( + Create a range partitioned table with multiple columns in the partition key: + +CREATE TABLE measurement_year_month ( + logdate date not null, + peaktemp int, + unitsales int +) PARTITION BY RANGE (EXTRACT(YEAR FROM DATE logdate), EXTRACT(MONTH FROM DATE logdate)); + + + Create a list partitioned table: CREATE TABLE cities ( @@ -1504,6 +1553,27 @@ CREATE TABLE measurement_y2016m07 + Create a few partitions of a range partitioned table with multiple + columns in the partition key: + +CREATE TABLE measurement_ym_older + PARTITION OF measurement_year_month + FOR VALUES FROM (unbounded, unbounded) TO (2016, 11); + +CREATE TABLE measurement_ym_y2016m11 + PARTITION OF measurement_year_month + FOR VALUES FROM (2016, 11) TO (2016, 12); + +CREATE TABLE measurement_ym_y2016m12 + PARTITION OF measurement_year_month + FOR VALUES FROM (2016, 12) TO (2017, 01); + +CREATE TABLE measurement_ym_y2017m01 + PARTITION OF measurement_year_month + FOR VALUES FROM (2017, 01) TO (2017, 02); + + + Create partition of a list partitioned table: CREATE TABLE cities_ab @@ -1705,6 +1775,25 @@ CREATE TABLE cities_ab_10000_to_100000 effect can be had using the OID feature. + + + <literal>PARTITION BY</> Clause + + + The PARTITION BY clause is a + PostgreSQL extension. + + + + + <literal>PARTITION OF</> Clause + + + The PARTITION OF clause is a + PostgreSQL extension. + + + -- 2.11.0