Unix Technical Forum

check_constraint and Extract not working?

This is a discussion on check_constraint and Extract not working? within the pgsql Sql forums, part of the PostgreSQL category; --> Just to be sure I am getting this right: I have a big table I want to partition: create ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Sql

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-19-2008, 03:24 PM
Fernando Hevia
 
Posts: n/a
Default check_constraint and Extract not working?

Just to be sure I am getting this right:

I have a big table I want to partition:

create table big_table (
row_date timestamp with time zone,
row_data character varying(80)
};

A nice solution would be to spread its rows in one of 12 child tables
according to which month the date field belongs to.
So my parent table is partitioned into 12 childs, one for each month:
child_1, child_2, ..., child_12.
My check constraints go like this:

ALTER TABLE child_1 ADD CONSTRAINT chk_child1_month CHECK (EXTRACT(MONTH
FROM row_date = 1:OUBLE PRECISION);
ALTER TABLE child_2 ADD CONSTRAINT chk_child2_month CHECK (EXTRACT(MONTH
FROM row_date) = 2:OUBLE PRECISION);
....

Well, the check_constraint exclusion won't work with these. I assume the
function Extract is the problem here and haven't been able to find a
workaround.

I have seen several examples where a table is partitioned by date but in
those cases the year is also specified. ie: child_200612, child_200701,
child_200702, etc. Though with this scenario I can avoid date functions in
the check constraint, this would force me to keep creating new child tables
from time to time.

I would really like to avoid that kind of maintenance, and for my case 12
partitions are quite enough.
Any suggestions how to achieve this otherwise?

Regards,
Fernando.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:35 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com