Sample Header Ad - 728x90

Best practice for distinguishing periods from timestamps in database tables

0 votes
0 answers
26 views
I am working with weather data. Historic data which was measured and then documented and on the other hand predicted data. In both cases it is possible for the data provider to either hand over data for periods or timestamps. Example: 1. Temperature is measured once every 10 minutes and is provided in °C 2. Global radiation is continuously measured for an hour and the sum is provided in kwh per m² The first example is a point in time measurement with a timestamp and the second is a continuous measurement with a period start and a period end. I would store this in a table like this: - Fk_Phenomenon_Id = 12 --> Temperature - Fk_Phenomenon_Id = 13 --> Global Radiation - Fk_Unit_Id = 3 --> °C - Fk_Unit_Id = 5 --> kwh per m² | ID | Fk_Phenomenon_Id | Value | Fk_Unit_Id | From | To | |----|----|----|----|----|-----| | 1 | 12 | 20 | 3 | 01.01.2024 10:00:00 | 01.01.2024 10:00:00 | | 2 | 13 | 0.15 | 5 | 01.01.2024 10:00:00 | 01.01.2024 11:00:00 | As you can see, the From and To columns are the same if it is a point in time. If it is a period they differ. There is however, also the possibility to use just one timestamp column and add a foreign key to a table which describes the period type. This table would be referenced by Fk_PeriodType_Id and it would contain entries like "leading hour", "trailing hour", "point in time", "trailing 10min" etc. Fk_PeriodType_Id is just one of many possibilities. I would like to have your advice on what is a good design for a table storing the described weather data. I am explicitly not asking for the best technical solution considering normalization and so on. I am focused on usability for automatisms and humans. Humans need to be able to read the table and filter it if needed and a programm accessing the database needs to be able to work with the data with reasonable performance, while the table still stays easily comprehensible for developers. The most helpful to me will be reports of experience with similar business needs. I have a solution in mind and am interested in what can go wrong when I apply it.
Asked by Merlin Nestler (159 rep)
Sep 30, 2024, 09:51 AM
Last activity: Sep 30, 2024, 11:07 AM