I set up a set of partitioned tables for documents at http://www.postgresql.org/docs/8.1/interactive/ddl-partitioning.html
CREATE TABLE t (year, a);
CREATE TABLE t_1980 ( CHECK (year = 1980) ) INHERITS (t);
CREATE TABLE t_1981 ( CHECK (year = 1981) ) INHERITS (t);
CREATE RULE t_ins_1980 AS ON INSERT TO t WHERE (year = 1980)
DO INSTEAD INSERT INTO t_1980 VALUES (NEW.year, NEW.a);
CREATE RULE t_ins_1981 AS ON INSERT TO t WHERE (year = 1981)
DO INSTEAD INSERT INTO t_1981 VALUES (NEW.year, NEW.a);
In my opinion, if I INSERT IN t (year, a) VALUES (1980, 5), it will go to t_1980, and if I INSERT IN B (year, a) VALUES (1981, 3), it will go to t_1981 . But my understanding seems to be wrong. Firstly, I can’t understand the following from the docs
"There is currently no easy way to indicate that rows should not be inserted in the main table. The CHECK (false) constraint in the main table will be inherited by all child tables, so they cannot be used for this purpose. One of the possibilities is to set the ON INSERT trigger to to the main table, which always causes an error. (Alternatively, you can use this trigger to redirect data to the appropriate child table, instead of using the ruleset as suggested above.) "
, , CHECK , TRIGGERs , INSERT ? , db? ? , , .
. ? ?
SELECT year, a FROM t WHERE year IN (1980, 1981);
: ,
", COPY . COPY , , . COPY , , , ."
COPY FROM , . TRIGGER.