A suggestion: don't store the duration. Calculate it from start_datetime and end_datetime as needed, or add a generated column. Then you don't need this code. Also consider using a single tstzrange column.
↧