Database Design – Appropriate Column Types for Dates and Dynamic Pricing Data

database-designdatatypes

What is the appropriate column(s) type(s) (trying to be database agnostic, but realize that could play into the answer) to store a months worth of pricing data (i.e. could be the daily hotel rate, etc.) as a snapshot for every day of the month?

The use case is to collect pricing data on a daily basis for a given month. For example, on February 1st, collect 28 (2/1 – 2/28) days worth of data, then on February 2nd, collect 27 (2/2 – 2/28) days worth of data,…,on February 28 collect 1 (2/28) day worth of data.

The reason for continually collecting the pricing data is that prices often change and given the example above so that historical pricing data is recorded (as opposed to just rewriting the pricing data for a given month).

Best Answer

For a relational database the correct way is to have a normalized table:

hotel_id         <whatever type>,
collection_date  date,
price_date       date,
price            numeric()

It sounds like you want to "compress" the price values into some sort of array. There are relational database systems which support the array type, PostgreSQL for one. Document stores (Mongo et al) have arrays as a natural part of their JSON support. Time series databases are optimized to store a changing metric (the room price) over time, by key (the hotel ID).

Many relational databases support compression and column-wise storage (Vertica, Teradata et al). These will space-optimize the storage of the values that are shared by many rows. This optimization is transparent to the application, which sends and receives rows oblivious to the DBMS's internal processing.