Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails PostgreSQL tsrange--重叠忽略等效范围?_Ruby On Rails_Postgresql_Overlap_Range Types - Fatal编程技术网

Ruby on rails PostgreSQL tsrange--重叠忽略等效范围?

Ruby on rails PostgreSQL tsrange--重叠忽略等效范围?,ruby-on-rails,postgresql,overlap,range-types,Ruby On Rails,Postgresql,Overlap,Range Types,我在Rails应用程序中有一个查询,如下所示: # 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 ex

我在Rails应用程序中有一个查询,如下所示:

# 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\u start
period\u end
创建的范围具有相同周期的记录。为什么呢?我想重叠检查是否有任何交叉点

但是,这里的问题是,不会返回与period_start和period_end创建的范围具有相同期间的任何记录

那不是真的。不确定你的问题是什么,但不是这样

SELECT
  tsrange(x,y),
  tsrange(x,y) && tsrange(x,y) AS overlaps
FROM ( VALUES
  ('yesterday'::timestamp, 'today'::timestamp)
) AS t(x,y);
                    tsrange                    | overlaps 
-----------------------------------------------+----------
 ["2017-04-24 00:00:00","2017-04-25 00:00:00") | t
(1 row)

繁荣!这是我测试中的一个问题,我正在测试的一个测试的范围相当于
period\u start..period\u start
而不是
period\u start..period\u end
。谢谢:)