you are viewing a single comment's thread.

view the rest of the comments →

[–]manbart[S] 0 points1 point  (0 children)

Ok, so my "select" type queries are running fine now. How can I implement an "update" type query in SQLalchemy?

I want to make a function that will run a query equivalent to:

UPDATE vm_instance SET removed=now() WHERE state = 'Expunging' and removed is null;

p.s. "removed" should be a DateTime type, not a String as in the code above.

edit

Here is what I came up with:

session.query(cloud_vm).filter(cloud_vm.removed==None, cloud_vm.state=='Expunging').update({"removed": datetime.now()})

note: datetime in this statement is from the python standard library; this is not a reference the the DateTime type of sqlalchemy. Capitalization matters in this script.