-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Range type support #7070
beikov
started this conversation in
Design Proposals
Range type support
#7070
-
Some DBMS support ranges natively i.e. have a custom SQL types for ranges: https://www.postgresql.org/docs/current/rangetypes.html
It would be cool if we could add support for this. If the DBMS doesn't support that, we could treat it like a composite type with properties min, max, minInclusive and maxInclusive that map to multiple columns through the custom composite type facility, similar to how we did it for OffsetDateTime/ZonedDateTime.
The idea is to introduce two interfaces:
final class Range<T>{ // Null indicates negative infinite @Nullable T getMin(); // Null indicates positive infinite @Nullable T getMax(); boolean isMinInclusive(); boolean isMaxInclusive(); static Range<T> of(T min, T max, boolean minInclusive, boolean maxInclusive); static Range<T> all(); static Range<T> min(T min, boolean inclusive); static Range<T> max(T max, boolean inclusive); }
In addition to adding the type, I suggest adding a overlaps predicate that checks if two ranges overlap and a contains predicate that checks if a value is within a range.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment