New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support PG ranges #676

Closed
sgrif opened this Issue Feb 11, 2017 · 3 comments

Comments

Projects
None yet
3 participants
@sgrif
Member

sgrif commented Feb 11, 2017

The SQL type should be Range<ST: CanAppearInRange>. We should provide an impl to/from SQL for (Bound<T>, Bound<T>) where T: FromSql<ST, Pg>. Bound is currently unstable, so we'll need to stick this behind the unstable feature. It appears to be on track for stabilization soon though, so I don't think we need to support any stable types.

For this to work with codegen we'll also need the following:

pub type Int4range = Range<Int4>;
pub type Int8range = Range<Int8>;
pub type Numrange = Range<Numeric>;
pub type Tsrange = Range<Timestamp>;
pub type Tstzrange = Range<Timestamptz>;
pub type Daterange = Range<Date>;

The impls for serialization/deserialization look pretty straightforward. Format appears to be a one byte set of flags (inclusive vs exclusive, whether start or end are unbounded), 4 byte length for upper value followed by data if present, 4 byte length for lower value followed by data if present.

@sgrif

This comment has been minimized.

Member

sgrif commented Feb 11, 2017

I wouldn't quite call this easy for newcomers, but it is at least fairly isolated.

@Eijebong

This comment has been minimized.

Member

Eijebong commented Apr 24, 2017

I'm working on that now, I just have some questions:

  • How do we treat infinity ?
  • OIDs ? Apparently each range has a different OID and arrays of ranges too. Should I request a metadata thing in the CanAppearInRange trait ?
@Eijebong

This comment has been minimized.

Member

Eijebong commented Aug 5, 2017

Fixed by #1021

@Eijebong Eijebong closed this Aug 5, 2017

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