If they are partitioned by date then query the parent table. If you want to create a new table:
create table another_table as
select *
from schedule_parent
where the_date between current_date - 6 and current_date
If you want to insert into an existent table:
insert into another_table
select *
from schedule_parent
where the_date between current_date - 6 and current_date
A partitioned table has a check constraint:
create table schedule_20121012 (
check (date the_date = date '20012-10-12')
) inherits (schedule_parent);
So when you query for a date from the parent table the planner knows which table to look for:
select * from schedule_parent where date the_date = date '20012-10-12'
I have a set of tables using inheritance. The table usuarios
has children partitioned by one of its columns. One of its children:
\d+ usuarios_25567
Table "public.usuarios_25567"
Column | Type | Modifiers | Storage | Description
---------+---------+-----------+---------+-------------
usuario | integer | not null | plain |
data | integer | not null | plain |
wus | integer | not null | plain |
pontos | real | not null | plain |
Indexes:
"ndx_usuarios_25567" UNIQUE, btree (usuario)
Check constraints:
"b25567" CHECK (data = 25567)
Foreign-key constraints:
"fk_usuarios_25567" FOREIGN KEY (data) REFERENCES datas(data_serial)
Inherits: usuarios
Has OIDs: no
Its check constraint is the data
column. Now look at the query plan when I use that column to filter the query on the parent table:
explain select * from usuarios where data = 25567;
QUERY PLAN
----------------------------------------------------------------------------------------------
Result (cost=0.00..26590.45 rows=1484997 width=16)
-> Append (cost=0.00..26590.45 rows=1484997 width=16)
-> Seq Scan on usuarios (cost=0.00..0.00 rows=1 width=16)
Filter: (data = 25567)
-> Seq Scan on usuarios_25567 usuarios (cost=0.00..26590.45 rows=1484996 width=16)
Filter: (data = 25567)
(6 rows)
It will only look at that table. Not the other hundreds of tables.