crystal-pg icon indicating copy to clipboard operation
crystal-pg copied to clipboard

add support for ranges

Open pascalbetz opened this issue 5 years ago • 3 comments

Implements Ranges (https://github.com/will/crystal-pg/issues/164)

This is as far as i can get with my limited Crystal knowhow...so i'll need some help to finish it.

pascalbetz avatar Oct 03 '20 22:10 pascalbetz

Thanks for putting this together. I'm not available for a couple of days, but I'll take a look at this next week and give feedback then :)

will avatar Oct 03 '20 23:10 will

Begin/Endless Ranges

Postgres supports "infinite" values for lower/upper boundary. This corresponds to begin/endless Ranges in Crystal. E.g.: [, 50) => nil..50 This makes the Range that gets created Range(T | Nil, T | Nil) Is this OK?

Another possibility would be to use the Datatypes MIN/MAX value (e.g. Int64::MIN) and make sure the boundary is inclusive: E.g.: [, 50) => Int32::MIN..50 so we would not create begin/endless Ranges. (This would not map what is in Postgres though, so I don't like it)

Empty Ranges

Postgres empty ranges are currently implemented as exclusive Ranges with the same value for lower and upper boundary. E.g. 0...0

The values I picked to build these empty ranges are arbitrary though and this does not map exactly what is stored in Postgres.

There is no way to differentiate between

(,)::int4range and [0,0]::int4range because both values end up in Range.new(0, 0).

What do you think?

pascalbetz avatar Oct 04 '20 12:10 pascalbetz

@will I plan on fixing the build and adding multiranges (Postgres 14) support if this can get merged. Let me know what you think.

pascalbetz avatar May 22 '21 08:05 pascalbetz