Insert a row in SQLAlchemy

Placed around houses on it, perhaps, the correct syntax did not work out.

All I want to do is insert a row into a table in SQLAlchemy. The documentation doesn't make sense to me:

class sqlalchemy.sql.expression.Insert(table, values=None, inline=False, bind=None, prefixes=None, returning=None, **kwargs) 

Closest i came

 userChoices = meta.Session.query(model.CompUserChoices).filter(model.CompUserChoices.inmptl_user_name == postdict['userid']).filter(model.CompUserChoices.inmptl_option_id == postdict['leg']).all() userChoices.insert({model.CompUserChoices.inmptl_user_name:postdict['userid']},\ {model.CompUserChoices.inmptl_option_id:postdict['leg']},\ {model.CompUserChoices.inmptl_comp_choice_id:newChoices[i]}) 

Can someone please tell me the correct syntax!

+4
source share
1 answer

I'm not sure I understand what exactly you are trying to do, but adding a line is usually no more difficult than creating a model object and adding it to the session.

 userChoices = model.CompUserChoices() # Do stuff on userChoices meta.Session.add(userChoices) meta.Session.commit() # if you have to commit manually 
+7
source

All Articles