diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_table.sgml index 58f8bf6d6a..e0f7cd9b93 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,10 +261,48 @@ 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 is + coercable 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 - specified using the WITH (OIDS) clause. + parent. If the parent is specified WITH OIDS then + the partitions must also explicitly specify WITH OIDS. Defaults and constraints can optionally be specified for each of the inherited columns. One can also specify table constraints in addition to those inherited from the parent. If a check constraint with the name @@ -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. @@ -1482,6 +1521,16 @@ CREATE TABLE measurement ( peaktemp int, unitsales int ) PARTITION BY RANGE (logdate); + + + + 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 logdate), EXTRACT(MONTH FROM logdate)); @@ -1503,6 +1552,27 @@ CREATE TABLE measurement_y2016m07 ) FOR VALUES FROM ('2016-07-01') TO ('2016-08-01'); + + 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: @@ -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. + + +