Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

169
Vistas
PostgreSQL tsrange -- overlap ignores equivalent ranges?

I have a query in my Rails app that looks like this:

# 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
}

However, the problem here is that any records who have the SAME period as the range created by period_start and period_end are not returned. Why is that? I thought overlap checked if there was any intersection at all?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

However, the problem here is that any records who have the SAME period as the range created by period_start and period_end are not returned.

That's not true. Not sure what your problem is, but that's not it.

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)
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda