With the following model, I can currently set postgres range data types in 
2 ways:

*Model:*
from sqlalchemy.dialects.postgresql import INT4RANGE

class Foo(Base):
    __tablename__ = 'foo'
    id = Column(Integer, primary_key=True)
    bar = Column(INT4RANGE)


*Method #1 - as string data type:*
foo.bar = '[{lower},{upper}]'.format(min=baz, max=qux)

*Results in the following being committed:*
INFO  [sqlalchemy.engine.base.Engine][Dummy-3] {'bar': *'[1, 10]'*, 
'foo_id': 1}

With the corresponding range being *'[1, 10]'*, as desired.



*Method #2 - as NumericRange data type:*
from psycopg2.extras import NumericRange

foo.bar = NumericRange(lower=baz, upper=qux, bounds='[]')

*Results in the following being committed:*
INFO  [sqlalchemy.engine.base.Engine][Dummy-4] {'bar': *NumericRange(1, 10, 
'[]')*, 'foo_id': 1}

With the corresponding range being *'[1, 11)'*.


The string method works as expected, but if I use it to set a range in the 
controller (say, from a form submission) and then return that range to the 
template engine, the `lower` and `upper` methods don't work because it's 
currently stored as a string type instead of a NumericRange type.

Is there a better way to do this (while still using the Range data types)?

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to