Time and date dimension in data warehouse

后端 未结 4 1193
灰色年华
灰色年华 2021-02-01 07:36

I\'m building a data warehouse. Each fact has it\'s timestamp. I need to create reports by day, month, quarter but by hours too. Looking at the examples I see that

4条回答
  •  花落未央
    2021-02-01 08:11

    My guess is that it depends on your reporting requirement. If you need need something like

    WHERE "Hour" = 10
    

    meaning every day between 10:00:00 and 10:59:59, then I would use the time dimension, because it is faster than

    WHERE date_part('hour', TimeStamp) = 10  
    

    because the date_part() function will be evaluated for every row. You should still keep the TimeStamp in the fact table in order to aggregate over boundaries of days, like in:

    WHERE TimeStamp between '2010-03-22 23:30' and '2010-03-23 11:15' 
    

    which gets awkward when using dimension fields.

    Usually, time dimension has a minute resolution, so 1440 rows.

提交回复
热议问题