Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23247

Usage PostgreSQL Multirange function with SQLAlchemy

$
0
0

I am using NUMMULTIRANGE field in my model. PostgreSQL has functions for this type described in docs. But I can't find implementation of this functionality in SQLAlchemy. I've read this part of documentation. There are a lot of useful properties for Range type, but nothing for Multirange.

My model looks like:

...from sqlalchemy.dialects.postgresql import Rangefrom sqlalchemy.dialects.postgresql import NUMMULTIRANGEclass Condition(Base):    range: Mapped[list[Range[Decimal]]] = mapped_column(NUMMULTIRANGE)

Is there way to use PostgreSQL built-in functions for multirange? For example, I would like to find lower and upper bounds of multirange, or use functions lower_inc, lower_inf. It seems like I have to iterate on my list of Ranges in this cases. May be you could suggest more efficient approach or I missed something in documentation.

I am using SQLAlchemy 2.0.28 and PostgreSQL 15.

And additional question: is there possibility of Range type in PostgreSQL to define Range excluding one value, equivalent to != expression? It would allow me to refuse from using multirange, because I have to specify expression like x != 6 with multirange '{(,6),(6,)}'?


Viewing all articles
Browse latest Browse all 23247

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>