Re: Table Partitioning: Sequence jump issue 10 in 10 with serialdatatype
От
Alban Hertroys
Тема
Re: Table Partitioning: Sequence jump issue 10 in 10 with serialdatatype
Дата
Msg-id
77283AFE-9FA4-488B-81CB-09E2512DAC11@gmail.com
Ответ на
Список
Дерево обсуждения
Table Partitioning: Sequence jump issue 10 in 10 with serialdatatype DrakoRod <drakoflames@hotmail.com>
Re: Table Partitioning: Sequence jump issue 10 in 10 with serial datatype "David G. Johnston" <david.g.johnston@gmail.com>
Re: Table Partitioning: Sequence jump issue 10 in 10 with serialdatatype DrakoRod <drakoflames@hotmail.com>
Re: Table Partitioning: Sequence jump issue 10 in 10 with serialdatatype Alban Hertroys <haramrae@gmail.com>
Re: Table Partitioning: Sequence jump issue 10 in 10 with serialdatatype DrakoRod <drakoflames@hotmail.com>
> On 14 Feb 2018, at 2:48, DrakoRod wrote: > CREATE OR REPLACE RULE inserts_customer_part1 > AS ON INSERT TO customers > WHERE new.id < 10000 > DO INSTEAD INSERT INTO customers_part1 SELECT NEW.*; > > CREATE OR REPLACE RULE inserts_customer_part2 > AS ON INSERT TO customers > WHERE new.id >= 10000 AND new.id < 20000 > DO INSTEAD INSERT INTO customers_part2 SELECT NEW.*; Here's your problem. Rules substitute values. Since you didn't provide an id in your insert, the id column gets substituted by the default value, which happens to call nextval. You have 3 references to new.id in your rules, so the sequence increments by 3. That's one of the reasons people usually advise to use triggers & procedures instead of rules. > dd=# SELECT * FROM customers; > id | name | other_data > ----+---------+------------ > 3 | XXXXXXx | YYYYYYYYYY > 7 | XXXXXXx | YYYYYYYYYY > 11 | XXXXXXx | YYYYYYYYYY > 15 | XXXXXXx | YYYYYYYYYY > 19 | XXXXXXx | YYYYYYYYYY > 23 | XXXXXXx | YYYYYYYYYY > (6 rows) Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.
В списке pgsql-general по дате отправления
От: Konstantin Evteev
Дата: