I have a transactions table:
CREATE TABLE transactions
(
id BIGSERIAL NOT NULL,
amount BIGINT,
value VARCHAR(200) NOT NULL,
created_date TIMESTAMP WITH TIME ZONE DEFAULT now()
) PARTITION BY RANGE (created_date);
Now i am creating two partitions:
CREATE TABLE transactions_y2021s01 PARTITION of transactions
FOR VALUES FROM ('2021-01-01') to ('2021-07-01')
;
CREATE TABLE transactions_y2021s02 PARTITION of transactions
FOR VALUES FROM ('2021-07-01') to ('2022-01-01')
;
Now i am inserting values in the table
insert into transactions (amount , value)
values (1,'xxxxxxxx'),
(2,'yyyyyyyyy'),
(3,'zzzzzzz');
Now i am do a select:
select * from transactions;
select * from transactions_y2021s02;
But I have the 3 rows in both tables, I have the information in parent and child table, this is the correct flow in a partition?, i don't think so.
select * from transactions;
1 , 1 , 'xxxxxxxx' , 2021-07-16 18:52:13
2 , 2 , 'yyyyyyyyy' , 2021-07-16 18:52:13
3 , 3 , 'zzzzzzz' , 2021-07-16 18:52:13
select * from transactions_y2021s02
1 , 1 , 'xxxxxxxx' , 2021-07-16 18:52:13
2 , 2 , 'yyyyyyyyy' , 2021-07-16 18:52:13
3 , 3 , 'zzzzzzz' , 2021-07-16 18:52:13
What is my problem with the partition.
and i create a rule but i have the same result, the insertion in both tables, i think that the data must be appear in child tables and not in parent table.
i use this rule, but not works:
CREATE or replace RULE transactions_insert_y2021s02 AS ON INSERT TO transactions
DO INSTEAD
INSERT INTO data.transactions_y2021s02 VALUES (NEW.*);
Thaks a lot
CREATE or replace RULE transactions_insert_y2021s02 AS ON INSERT TO data.transactions DO INSTEAD INSERT INTO data.transactions_y2021s02 VALUES (NEW.*);select * from only transactionsif want to see only rows physically in the parent, (which will be none when using declarative partitioning).