Last active
June 28, 2023 04:17
-
-
Save brainwire/50b9d5c85fd10b8bea40 to your computer and use it in GitHub Desktop.
Postgresql's tsrange Range Type with Rails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://www.postgresql.org/docs/devel/static/rangetypes.html | |
create_table :Room do |t| | |
t.daterange :availability | |
end | |
Room.create(availability: (Date.today..Float::INFINITY)) | |
Room.first.availability # => Wed, 19 Sep 2012..Infinity | |
connection.execute(%q{ | |
alter table events | |
alter column "when" | |
type tsrange using tsrange(lower("when"), upper("when")) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice, thanks