It's a bad idea to use names of basic functions (
sum
) or data types (timestamp
) as column names.BETWEEN
includes lower and upper bound. Often, you would rather include the lower, but exclude the upper bound.There is a tiny chance for a race condition in the above function. To be prepared for heavy concurrent load, consider this related answer:
Is SELECT or INSERT in a function prone to race conditions?Is SELECT or INSERT in a function prone to race conditions?
- PostgreSQL EXCLUDE USING error: Data type integer has no default operator class
- Optimizing queries on a range of timestamps (two columns)
- 2 B-tree indices OR 1 GiST index on tsrange -- which will perform better?
- Preventing adjacent/overlapping entries with EXCLUDE in PostgreSQLPreventing adjacent/overlapping entries with EXCLUDE in PostgreSQL