example now includes your second question:

from sqlalchemy import Sequence, create_engine, MetaData, Column, Integer
from sqlalchemy.ext.declarative import declarative_base


Base = declarative_base()

class Model(Base):
    __tablename__ = 'model'
    col = Column(Integer, Sequence('seq'), primary_key=True)


if __name__ == "__main__":
    e = create_engine('postgresql://rforkel@/test1', echo=True)
    Base.metadata.bind = e
    s = Sequence('name', metadata=Base.metadata)
    Base.metadata.create_all()
    print list(e.execute(s.next_value()))[0][0]

    for col in Model.__table__.columns:
        if col.name == 'col':
            print list(e.execute(col.default.next_value()))[0][0]


On Tue, May 29, 2012 at 8:58 AM, Chris Withers <ch...@simplistix.co.uk> wrote:
> Hi All,
>
> How do I create a postgres sequence independent of a table using sqlalchemy?
>
> How do I select the next value from a sequence that forms part of a postgres
> table, starting with the SQLAlchemy Table object?
>
> cheers,
>
> Chris
>
> --
> Simplistix - Content Management, Batch Processing & Python Consulting
>            - http://www.simplistix.co.uk
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> To unsubscribe from this group, send email to
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sqlalchemy?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to