Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/sqlalchemy/dialects/postgresql/ranges.py: 70%
40 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:35 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:35 +0000
1# Copyright (C) 2013-2023 the SQLAlchemy authors and contributors
2# <see AUTHORS file>
3#
4# This module is part of SQLAlchemy and is released under
5# the MIT License: https://www.opensource.org/licenses/mit-license.php
7from ... import types as sqltypes
10__all__ = ("INT4RANGE", "INT8RANGE", "NUMRANGE")
13class RangeOperators(object):
14 """
15 This mixin provides functionality for the Range Operators
16 listed in the Range Operators table of the `PostgreSQL documentation`__
17 for Range Functions and Operators. It is used by all the range types
18 provided in the ``postgres`` dialect and can likely be used for
19 any range types you create yourself.
21 __ https://www.postgresql.org/docs/current/static/functions-range.html
23 No extra support is provided for the Range Functions listed in the Range
24 Functions table of the PostgreSQL documentation. For these, the normal
25 :func:`~sqlalchemy.sql.expression.func` object should be used.
27 """
29 class comparator_factory(sqltypes.Concatenable.Comparator):
30 """Define comparison operations for range types."""
32 def __ne__(self, other):
33 "Boolean expression. Returns true if two ranges are not equal"
34 if other is None:
35 return super(RangeOperators.comparator_factory, self).__ne__(
36 other
37 )
38 else:
39 return self.expr.op("<>", is_comparison=True)(other)
41 def contains(self, other, **kw):
42 """Boolean expression. Returns true if the right hand operand,
43 which can be an element or a range, is contained within the
44 column.
46 kwargs may be ignored by this operator but are required for API
47 conformance.
48 """
49 return self.expr.op("@>", is_comparison=True)(other)
51 def contained_by(self, other):
52 """Boolean expression. Returns true if the column is contained
53 within the right hand operand.
54 """
55 return self.expr.op("<@", is_comparison=True)(other)
57 def overlaps(self, other):
58 """Boolean expression. Returns true if the column overlaps
59 (has points in common with) the right hand operand.
60 """
61 return self.expr.op("&&", is_comparison=True)(other)
63 def strictly_left_of(self, other):
64 """Boolean expression. Returns true if the column is strictly
65 left of the right hand operand.
66 """
67 return self.expr.op("<<", is_comparison=True)(other)
69 __lshift__ = strictly_left_of
71 def strictly_right_of(self, other):
72 """Boolean expression. Returns true if the column is strictly
73 right of the right hand operand.
74 """
75 return self.expr.op(">>", is_comparison=True)(other)
77 __rshift__ = strictly_right_of
79 def not_extend_right_of(self, other):
80 """Boolean expression. Returns true if the range in the column
81 does not extend right of the range in the operand.
82 """
83 return self.expr.op("&<", is_comparison=True)(other)
85 def not_extend_left_of(self, other):
86 """Boolean expression. Returns true if the range in the column
87 does not extend left of the range in the operand.
88 """
89 return self.expr.op("&>", is_comparison=True)(other)
91 def adjacent_to(self, other):
92 """Boolean expression. Returns true if the range in the column
93 is adjacent to the range in the operand.
94 """
95 return self.expr.op("-|-", is_comparison=True)(other)
97 def __add__(self, other):
98 """Range expression. Returns the union of the two ranges.
99 Will raise an exception if the resulting range is not
100 contiguous.
101 """
102 return self.expr.op("+")(other)
105class INT4RANGE(RangeOperators, sqltypes.TypeEngine):
106 """Represent the PostgreSQL INT4RANGE type."""
108 __visit_name__ = "INT4RANGE"
111class INT8RANGE(RangeOperators, sqltypes.TypeEngine):
112 """Represent the PostgreSQL INT8RANGE type."""
114 __visit_name__ = "INT8RANGE"
117class NUMRANGE(RangeOperators, sqltypes.TypeEngine):
118 """Represent the PostgreSQL NUMRANGE type."""
120 __visit_name__ = "NUMRANGE"
123class DATERANGE(RangeOperators, sqltypes.TypeEngine):
124 """Represent the PostgreSQL DATERANGE type."""
126 __visit_name__ = "DATERANGE"
129class TSRANGE(RangeOperators, sqltypes.TypeEngine):
130 """Represent the PostgreSQL TSRANGE type."""
132 __visit_name__ = "TSRANGE"
135class TSTZRANGE(RangeOperators, sqltypes.TypeEngine):
136 """Represent the PostgreSQL TSTZRANGE type."""
138 __visit_name__ = "TSTZRANGE"