I'm trying to get sqlalchemy to accept some more complex behavior on an insert, and can't figure out the idiomatic way to do it. To simplify things, I was just trying to add a literal string to the end of the query, but can't find a valid way to do it. I've seen the "text()" function use to add string literals to queries, but it wouldn't work the way I am using it. Here is an example of what I'm trying to do (this won't compile, but captures the idea at least...)
from sqlalchemy import *
metadata = MetaData()
user = Table('user', metadata,
Column('user_id', Integer, primary_key = True),
Column('likes', Integer, nullable = False),
Column('last_liked', TIMESTAMP, nullable = False),
)
userid = 1
newlikes = 5
user.insert().values(user_id=userid, likes=newlikes) +
text("ON DUPLICATE KEY UPDATE last_liked=NOW(), likes = likes + " + newlikes)
Any recommendations would be appreciated.