这已被添加到官方文档:
@L_301_2@
不得不四处寻找,但如果有疑问,请检查测试! SQLAlchemy tests for the range types使用基础psycopg2 types.
from psycopg2.extras import NumericRange from sqlalchemy import create_engine,Column,Integer from sqlalchemy.dialects.postgresql import INT4RANGE from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker engine = create_engine('postgresql:///example',echo=True) Session = sessionmaker(bind=engine) session = Session() Base = declarative_base(bind=engine) class Example(Base): __tablename__ = 'example' id = Column(Integer,primary_key=True) window = Column(INT4RANGE,nullable=False) Base.Metadata.create_all() session.add(Example(window=NumericRange(2,6))) session.add(Example(window=NumericRange(4,8))) session.commit()