What is best practice for representing time intervals in a data warehouse?

后端 未结 3 1963
甜味超标
甜味超标 2021-02-03 12:50

In particular I am dealing with a Type 2 Slowly Changing Dimension and need to represent the time interval a particular record was active for, i.e. for each record I have a

3条回答
  •  Happy的楠姐
    2021-02-03 13:32

    I have seen both closed and half-open versions in use. I prefer half-open for the reasons you have stated.

    In my opinion the half-open version it makes the intended behaviour clearer and is "safer". The predicate ( a <= x < b ) clearly shows that b is intended to be outside the interval. In contrast, if you use closed intervals and specify (x BETWEEN a AND b) in SQL then if someone unwisely uses the enddate of one row as the start of the next, you get the wrong answer.

    Make the latest end date default to the largest date your DBMS supports rather than null.

提交回复
热议问题