Skip to content

RangeBound does not faithfully model Postgres range bounds #267

Description

@fieldstrength

RangeBound has too many constructors.

In general Postgres ranges do not have the concept of PosInfinity or NegInfinity. So it would be preferable for these to be replaced with a singe constructor which could be called Unbound. This would have the appealing property of disallowing obviously nonsensical values like. (+infinity,-infinity)

From the relevant portion of the documentation

some element types have a notion of “infinity”, but that is just another value so far as the range type mechanisms are concerned. For example, in timestamp ranges, [today,] means the same thing as [today,). But [today,infinity] means something different from [today,infinity) — the latter excludes the special timestamp value infinity.

Activity

  1. lpsmith commented on Aug 13, 2018

    @lpsmith
    Owner

    Well, PGRange PosInfinity NegInfinity is a perfectly sensible value, and will be rendered to postgresql as 'empty'. In fact, that's actually the definition of empty in postgresql-simple. The range module itself will never produce either +infinity or -infinity in a postgresql value, but rather translate that to an appropriate syntax.

    You might want to look at the actual implementation of this module.

  2. fieldstrength commented on Aug 14, 2018

    @fieldstrength
    Author

    That does not seem like "sensible value" to me. It has no reasonable interpretation as a range. Postgres does the reasonable thing and rejects something like that, even for range types that do happen to have infinities.

    Ive glanced in the module. My interest is mainly as a user of the library and I don't have much knowledge of the internals. I don't claim the library generates invalid SQL, but I claim the data type that's exposed is the wrong one. I think its important that types accurately reflect what they do, and in particular here the type that leads one to wrong conclusions about the Postgres feature it represents, as it did for me.

    Is there some benefit to choosing this representation that does not correspond to the values that Postgres actually supports? I have a hard time imagining one.

    I appreciate the library, and don't mean to imply an imposition on your time. I would consider writing a patch sometime if it would be accepted. If not I'm interested in the reasoning.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions