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 $ -->
2
2
3
3
<chapter id="ddl">
4
4
<title>Data Definition</title>
@@ -2466,8 +2466,9 @@ CREATE TABLE measurement_y2008m01 ( ) INHERITS (measurement);
2466
2466
2467
2467
<listitem>
2468
2468
<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:
2471
2472
2472
2473
<programlisting>
2473
2474
CREATE TABLE measurement_y2006m02 (
@@ -2550,12 +2551,12 @@ CREATE TRIGGER insert_measurement_trigger
2550
2551
CREATE OR REPLACE FUNCTION measurement_insert_trigger()
2551
2552
RETURNS TRIGGER AS $$
2552
2553
BEGIN
2553
- IF ( logdate >= DATE '2006-02-01' AND logdate < DATE '2006-03-01' ) THEN
2554
+ IF ( NEW. logdate >= DATE '2006-02-01' AND NEW. logdate < DATE '2006-03-01' ) THEN
2554
2555
INSERT INTO measurement_y2006m02 VALUES (NEW.*);
2555
- ELSIF ( logdate >= DATE '2006-03-01' AND logdate < DATE '2006-04-01' ) THEN
2556
+ ELSIF ( NEW. logdate >= DATE '2006-03-01' AND NEW. logdate < DATE '2006-04-01' ) THEN
2556
2557
INSERT INTO measurement_y2006m03 VALUES (NEW.*);
2557
2558
...
2558
- ELSIF ( logdate >= DATE '2008-01-01' AND logdate < DATE '2008-02-01' ) THEN
2559
+ ELSIF ( NEW. logdate >= DATE '2008-01-01' AND NEW. logdate < DATE '2008-02-01' ) THEN
2559
2560
INSERT INTO measurement_y2008m01 VALUES (NEW.*);
2560
2561
ELSE
2561
2562
RAISE EXCEPTION 'Date out of range. Fix the measurement_insert_trigger() function!';
@@ -2576,6 +2577,15 @@ LANGUAGE plpgsql;
2576
2577
it doesn't need to be updated as often, since branches can be
2577
2578
added in advance of being needed.
2578
2579
</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>
2579
2589
</listitem>
2580
2590
</orderedlist>
2581
2591
</para>
0 commit comments