I'm currently working on using the ORM features of sqlalchemy with a legacy 
database table. The table can be roughly described like this:

class APIResponse(Base):
    __tablename__ = 'responses'
    id = Column(Text, primary_key=True)
    version = Column(Integer, primary_key=True)
    payload = Column(JSONB, nullable=False)
    created_at = Column(DateTime, nullable=False)


The table stores JSON payloads where the primary key is determined by the 
combination of the id and version columns (as a composite primary key). 
What I'm trying to work out is whether it's possible to have the value of 
the version column be the result of func.max(APIResponse.version) + 1, that 
is, MAX()+1 to increment the version.

This is running on Postgresql, and so I took a look at the sequence 
support, but that appears to be a table wide sequence, and not keyed off a 
value (ie: I couldn't have 10000 id's each mapping to a sequence to 
generate versions).

I'm not sure if I've explained myself clearly, but I'm a little stumped as 
to how I might achieve this.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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.

Reply via email to