0
我在我的Rails應用程序的查詢,看起來像這樣:PostgreSQL tsrange - 重疊忽略等效範圍?
# Returns any records whose period intersect the specified time
# @see https://www.postgresql.org/docs/9.3/static/rangetypes.html
# @see https://www.postgresql.org/docs/9.3/static/functions-range.html
# @note The '()' means exclude both sides of the range
#
# @param period_start [DateTime,Time] Start of the range
# @param period_end [DateTime,Time] End of the range
scope :overlapping, ->(period_start, period_end) {
where(
"#{table_name}.period && tsrange(:period_start, :period_end, '()')",
period_start: Time.at(period_start.to_i), # Caps precision to the second
period_end: Time.at(period_end.to_i) # Caps precision to the second
).distinct
}
然而,這裏的問題是,誰具有相同的週期由period_start
和period_end
創建的範圍內的任何記錄都沒有回來。這是爲什麼?我認爲重疊檢查是否有任何交集?
熱潮!在我的測試中,這是一個問題,我測試的那個人的範圍相當於'period_start..period_start'而不是'period_start..period_end'。謝謝 :) – trevorhinesley