I have a business entity representing a weather forecast for a given location at a given time. There are different kinds of weather parameters that are forecasted for the given location and time, for example air temperature, air pressure, wind speed etc. Not all parameters will be guaranteed to be available, and I want to stay flexible to add new parameters.
If I want to design a table that fits these needs, I could use the following approach (one line per entity):
myforecasttable:
- location_id PRIMARY
- timestamp PRIMARY
- airtemperature
- airpressure
- windspeed
- etc.
Or I could use the following approach (multiple lines per entity):
myforecasttable:
- location_id PRIMARY
- timestamp PRIMARY
- parameter_type PRIMARY
- value
...where parameter_type
will be an enum
or string
representing the concrete type of weather parameter (like airtemperature, air pressure etc.).
With the first approach, I will get NULL
values in different columns, but it will be easier to query. With the second approach, it will be much easier to add new weather parameters, but the queries will probably be harder.
Are there any pros and cons with these designs? How can I choose which database design is the best for my use case?