diff options
author | Tom Lane | 2007-12-03 04:59:55 +0000 |
---|---|---|
committer | Tom Lane | 2007-12-03 04:59:55 +0000 |
commit | f6f576ebb25bde1b6f13010a1febf1da1f6333d4 (patch) | |
tree | 2f8b069c6b4b94a5248e1b8c7a35258c305725e7 | |
parent | 62e8f0b910ed438c3eea05e7e3cb8addbe345e62 (diff) |
Improve partitioning example, per Itagaki Takahiro.
-rw-r--r-- | doc/src/sgml/ddl.sgml | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml index 5a4f50a90e..d27260b906 100644 --- a/doc/src/sgml/ddl.sgml +++ b/doc/src/sgml/ddl.sgml @@ -2466,8 +2466,9 @@ CREATE TABLE measurement_y2008m01 ( ) INHERITS (measurement); <listitem> <para> - We must add non-overlapping table constraints, so that our - table creation script becomes: + We must provide non-overlapping table constraints. Rather than + just creating the partition tables as above, the table creation + script should really be: <programlisting> CREATE TABLE measurement_y2006m02 ( @@ -2550,12 +2551,12 @@ CREATE TRIGGER insert_measurement_trigger CREATE OR REPLACE FUNCTION measurement_insert_trigger() RETURNS TRIGGER AS $$ BEGIN - IF ( logdate >= DATE '2006-02-01' AND logdate < DATE '2006-03-01' ) THEN + IF ( NEW.logdate >= DATE '2006-02-01' AND NEW.logdate < DATE '2006-03-01' ) THEN INSERT INTO measurement_y2006m02 VALUES (NEW.*); - ELSIF ( logdate >= DATE '2006-03-01' AND logdate < DATE '2006-04-01' ) THEN + ELSIF ( NEW.logdate >= DATE '2006-03-01' AND NEW.logdate < DATE '2006-04-01' ) THEN INSERT INTO measurement_y2006m03 VALUES (NEW.*); ... - ELSIF ( logdate >= DATE '2008-01-01' AND logdate < DATE '2008-02-01' ) THEN + ELSIF ( NEW.logdate >= DATE '2008-01-01' AND NEW.logdate < DATE '2008-02-01' ) THEN INSERT INTO measurement_y2008m01 VALUES (NEW.*); ELSE RAISE EXCEPTION 'Date out of range. Fix the measurement_insert_trigger() function!'; @@ -2576,6 +2577,15 @@ LANGUAGE plpgsql; it doesn't need to be updated as often, since branches can be added in advance of being needed. </para> + + <note> + <para> + In practice it might be best to check the newest partition first, + if most inserts go into that partition. For simplicity we have + shown the trigger's tests in the same order as in other parts + of this example. + </para> + </note> </listitem> </orderedlist> </para> |