Skip to content

Instantly share code, notes, and snippets.

@brainwire
Last active June 28, 2023 04:17
Show Gist options
  • Save brainwire/50b9d5c85fd10b8bea40 to your computer and use it in GitHub Desktop.
Save brainwire/50b9d5c85fd10b8bea40 to your computer and use it in GitHub Desktop.
Postgresql's tsrange Range Type with Rails
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"))
})
@hdchinh-freec
Copy link

Nice, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment