Consider a prices table with these columns:
id integer primary key
product_id integer -- foreign key
start_date date not null
end_date date not null
quantity integer
price numeric
I'd like the database to enforce the rule that a product can only have one price at a specific quantity in a date range (via where <date> BETWEEN start_date AND end_date).
Is this kind of range-based constraint doable?
daterangeis exactly the same since it's exclusive lower bound, but that's easy to fix. Should I really be migrating my data to use adaterangecolumn type (can make that a separate question if that's better) or is this two-column thing reasonable? – spike Aug 10 '15 at 15:57(product_id, start_date). With a daterange, that would have to be an index on(product_id, lower(range_column))– ypercubeᵀᴹ Aug 10 '15 at 16:07