Replies: 1 comment 1 reply
-
This already works, but you need to explicitly cast the value: DB.extension :pg_range
Sequel.extension :pg_range_ops
range = Sequel.pg_range(Date.today..Date.today+1, :tsrange)
DB.get(range.op.contains(Sequel.cast(Time.now, Time)))
# SELECT (tsrange('2025-03-13','2025-03-14','[]') @> CAST('2025-03-13 08:50:36.987591-0700' AS timestamp)) AS "v" LIMIT 1 The issue is without the explicit cast, PostgreSQL assumes range type. Sequel ships with an DB.extension :pg_range
DB.extension :auto_cast_date_and_time
Sequel.extension :pg_range_ops
range = Sequel.pg_range(Date.today..Date.today+1, :tsrange)
DB.get(range.op.contains(Time.now))
# SELECT (tsrange(DATE '2025-03-13',DATE '2025-03-14','[]') @> TIMESTAMP '2025-03-13 08:53:44.605007-0700') AS "v" LIMIT 1 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Given I am using Sequel.Model and have a "tsrange" column called "validty_period", I can query for overlapping ranges like this:
My.where(Sequel.pg_range(:validity_period).contains(start..end)
. This uses the "@>" operator.I would like to be able to pass a single timestamp (Time instance) to the contains method, which should be possible according to the documentation so I can call
My.where(Sequel.pg_range(:validity_period).contains(time)
.Our current workaround is using
.contains(time..time)
, but being able to pass a single timestamp would be more intuitive.Would you be open to extend the API to support passing a single value?
Beta Was this translation helpful? Give feedback.
All reactions