sql - How to store an event is happening from 2017-08-20 to 2017-08-24? What data type? -
say event happening 2017-08-20 2017-08-24.
i've seen apis store , return like:
date_start: date date_end: date however might case these apis using mongodb or other nosql without types.
should doing above or using data types interval (not sure of example of it's for) or daterange (seems likely) instead?
range types might best - either daterange, tsrange or tstzrange
8.17.1. built-in range types
postgresql comes following built-in range types:
int4range — range of integer
int8range — range of bigint
numrange — range of numeric
tsrange — range of timestamp without time zone
tstzrange — range of timestamp time zone
daterange — range of date
gist , sp-gist indexes can created table columns of range types.
can create cxclusion constraints ranges allow specification of constraints such "non-overlapping" on range type.
there many built-in functions , operators available range types.
drawback ranges not part of sql standard , not supported other databases, may have troubles if decide day move rdbms.
Comments
Post a Comment