rails / rails

Ruby on Rails

Home Page:https://rubyonrails.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No longer map PostgreSQL ranges to Ruby ranges. Introduce a new PGRange type.

senny opened this issue · comments

This is a follow up to #13793.

We currently map all PostgreSQL ranges directly to Ruby ranges. Because the Ruby range is inferior to the PostgreSQL range we can not make an exact conversion. This leads to the following issues:

  • Ruby ranges to not support exclusive lower bounds. We have some magic that tries to deal with that but it's not accurate and not complete: See here, here and here
  • Ruby ranges do not support unbound beginnings or ends. We are trying to simulate this using X::Infinity values. However those infinity values do not exist for every possible range type. See #12694 for an example.

The solution is to introduce a new type called PGRange. The PostgresqlAdapter will no longer map to Ruby ranges but to this new type. We can model that type to easily support unbound ranges and exclusive beginnings and endings. The PGRange type should act mostly like a Ruby range. For cases where you are dependent on an actual Ruby range and for backwards compatibility we add a method to convert a PGRange to a Ruby range: to_range.

@tenderlove I wrote down my thoughts so you can dispatch this one to one of your students.

#13793 is merged. @tenderlove a student could start to work on this.

Sequel has this already: https://github.com/jeremyevans/sequel/blob/master/lib/sequel/extensions/pg_range.rb

Would be nice to share some of this postgresql oid/type code between sequel, activerecord, and the activerecord-jdbc projects. All of them have subtly different support for these postgresql types.

Working on this.

@jefflai2, I think @Fortisque was working on this... though he hasn't been in touch lately, so may not have gotten anywhere with it.

On that basis, I think it's fine for you to go ahead on it... just mentioning in case you want to check in with him.

@matthewd Thanks for the heads up, I'll be working on this.

Follow up #15098