I'm sorry sqlalchemy hasn't fully clicked for me yet. I'm still stuck on this.
A I meant to be translating the sql that Michael has suggested into an ORM query? This is as far as I have got which results in : NameError: name 'Issues' is not defined Even then I still don't see how to get the "where" clause into the select. from sqlalchemy import Column, String, Integer, DateTime, Boolean from db_global import db from sqlalchemy.sql import func, select class Issues(db.Base): __tablename__ = 'issues' id = Column(String, primary_key=True) thread_id = Column(String, nullable=False) sequence_number = Column(Integer, default=select([func.coalesce(func.max(Issues.sequence_number) + 1, 1)])) -- 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 https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.