How to detect time-overlapping-records in Postgres + Rails
Public
16 Jan 12:06

Model
  .where("TSRANGE(?, ?, '()') && TSRANGE(starts_at, ends_at, '()')", starts_at, ends_at)
  .where.not(id: record_id)
  .exists?

Both starts_at and ends_at columns should be indexed.

Comments

Empty! You must sign in to add comments.