Closed
Description
Describe the use case
I'm upgrading from SQLAlchemy 1.4 where the psycopg2 range types are used, and Range.__contains__
is implemented for those.
Databases / Backends / Drivers targeted
PostgreSQL dialect
Example Use
the psycopg2 types implement it, but if selecting a column that is e.g. INT4RANGE
then the sqlalchemy Range
type is returned:
>>> range1 = conn.scalar(select(func.int4range(1, 10)))
>>> range1
NumericRange(1, 10, '[)')
>>> 3 in range1
True
>>> 12 in range1
False
>>> range2 = conn.scalar(select(type_coerce(func.int4range(1, 10), INT4RANGE)))
>>> range2
Range(lower=1, upper=10, bounds='[)', empty=False)
>>> 3 in range2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: argument of type 'Range' is not iterable
Additional context
I'll open a PR
Activity
[-]Implement Range.__contains__[/-][+]Range type does not implement __contains__[/+]sqla-tester commentedon Nov 15, 2024
Frazer McLean has proposed a fix for this issue in the main branch:
Add Range.contains https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/5596
sqla-tester commentedon Nov 15, 2024
Frazer McLean has proposed a fix for this issue in the rel_2_0 branch:
Add Range.contains https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/5597
Add Range.__contains__
Add Range.__contains__