1

UPDATE table1 SET column1 = column2 WHERE column3 = 'abc';

How do I execute the above query in sql alchemy ORM

table1 = Table('table1', metadata,
    Column("column1",     SmallInteger(),     nullable=False, autoincrement=False),
    Column("column2",     SmallInteger(),    nullable=False, autoincrement=False),
    Column("column3",     String(length=255), nullable=False)
)

class Table1(object):
    pass
mapper(Table1, table1)

1 Answer 1

1
DBSession.query(table1).filter_by(column3 = 'abc').update({"column1":column2}, synchronize_session=False)

use this

where  ==== filter_by
table1 === class containing the table1 schema
update command with columns as key in query

http://docs.sqlalchemy.org/en/latest/core/dml.html follow this link will guide you

Sign up to request clarification or add additional context in comments.

1 Comment

I get this error AttributeError: Neither 'InstrumentedAttribute' object nor 'Comparator' object has an attribute 'self_group'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.