Skip to content

Commit 57da4cc

Browse files
committed
Improve partitioning example, per Itagaki Takahiro.
1 parent 531f586 commit 57da4cc

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

doc/src/sgml/ddl.sgml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/ddl.sgml,v 1.78 2007/12/02 19:20:32 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/ddl.sgml,v 1.79 2007/12/03 04:59:55 tgl Exp $ -->
22

33
<chapter id="ddl">
44
<title>Data Definition</title>
@@ -2466,8 +2466,9 @@ CREATE TABLE measurement_y2008m01 ( ) INHERITS (measurement);
24662466

24672467
<listitem>
24682468
<para>
2469-
We must add non-overlapping table constraints, so that our
2470-
table creation script becomes:
2469+
We must provide non-overlapping table constraints. Rather than
2470+
just creating the partition tables as above, the table creation
2471+
script should really be:
24712472

24722473
<programlisting>
24732474
CREATE TABLE measurement_y2006m02 (
@@ -2550,12 +2551,12 @@ CREATE TRIGGER insert_measurement_trigger
25502551
CREATE OR REPLACE FUNCTION measurement_insert_trigger()
25512552
RETURNS TRIGGER AS $$
25522553
BEGIN
2553-
IF ( logdate &gt;= DATE '2006-02-01' AND logdate &lt; DATE '2006-03-01' ) THEN
2554+
IF ( NEW.logdate &gt;= DATE '2006-02-01' AND NEW.logdate &lt; DATE '2006-03-01' ) THEN
25542555
INSERT INTO measurement_y2006m02 VALUES (NEW.*);
2555-
ELSIF ( logdate &gt;= DATE '2006-03-01' AND logdate &lt; DATE '2006-04-01' ) THEN
2556+
ELSIF ( NEW.logdate &gt;= DATE '2006-03-01' AND NEW.logdate &lt; DATE '2006-04-01' ) THEN
25562557
INSERT INTO measurement_y2006m03 VALUES (NEW.*);
25572558
...
2558-
ELSIF ( logdate &gt;= DATE '2008-01-01' AND logdate &lt; DATE '2008-02-01' ) THEN
2559+
ELSIF ( NEW.logdate &gt;= DATE '2008-01-01' AND NEW.logdate &lt; DATE '2008-02-01' ) THEN
25592560
INSERT INTO measurement_y2008m01 VALUES (NEW.*);
25602561
ELSE
25612562
RAISE EXCEPTION 'Date out of range. Fix the measurement_insert_trigger() function!';
@@ -2576,6 +2577,15 @@ LANGUAGE plpgsql;
25762577
it doesn't need to be updated as often, since branches can be
25772578
added in advance of being needed.
25782579
</para>
2580+
2581+
<note>
2582+
<para>
2583+
In practice it might be best to check the newest partition first,
2584+
if most inserts go into that partition. For simplicity we have
2585+
shown the trigger's tests in the same order as in other parts
2586+
of this example.
2587+
</para>
2588+
</note>
25792589
</listitem>
25802590
</orderedlist>
25812591
</para>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy