Skip to content

How to implement postresql ranges #907

Discussion options

You must be logged in to vote

Well for that you will need to create your own class NumRange and customize it for your usage.
Here is a quick example of what you could do:

class NumRange:
    def __init__(self, lower: Optional[int] = None, upper: Optional[int] = None, bounds: str = '[]'):
        assert not (lower is None and upper is None), 'Both lower and upper bounds cannot be None'
        assert bounds in ['[]', '()', '(]', '[)'], 'Invalid bounds'

        self.lower = lower
        self.upper = upper
        self.bounds = bounds

    def __repr__(self):
        return f'NumRange({self.lower}, {self.upper}, {self.bounds})'

    def __str__(self):
        return f'{self.bounds[0]}{self.lower if self.lower else ""};{s…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@DanielAndreasen
Comment options

Answer selected by DanielAndreasen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
2 participants