r"""Perform an UPDATE with an arbitrary WHERE clause. Updates rows matched by this query in the database. E.g.:: sess.query(User).filter(User.age == 25).update( {User.age: User.age - 10}, synchronize_session=False ) sess.query(U
(
self,
values: Dict[_DMLColumnArgument, Any],
synchronize_session: SynchronizeSessionArgument = "auto",
update_args: Optional[Dict[Any, Any]] = None,
)
| 3287 | return result.rowcount |
| 3288 | |
| 3289 | def update( |
| 3290 | self, |
| 3291 | values: Dict[_DMLColumnArgument, Any], |
| 3292 | synchronize_session: SynchronizeSessionArgument = class="st">"auto", |
| 3293 | update_args: Optional[Dict[Any, Any]] = None, |
| 3294 | ) -> int: |
| 3295 | rclass="st">"""Perform an UPDATE with an arbitrary WHERE clause. |
| 3296 | |
| 3297 | Updates rows matched by this query in the database. |
| 3298 | |
| 3299 | E.g.:: |
| 3300 | |
| 3301 | sess.query(User).filter(User.age == 25).update( |
| 3302 | {User.age: User.age - 10}, synchronize_session=False |
| 3303 | ) |
| 3304 | |
| 3305 | sess.query(User).filter(User.age == 25).update( |
| 3306 | {class="st">"age": User.age - 10}, synchronize_session=class="st">"evaluate" |
| 3307 | ) |
| 3308 | |
| 3309 | .. warning:: |
| 3310 | |
| 3311 | See the section :ref:`orm_expression_update_delete` for important |
| 3312 | caveats and warnings, including limitations when using arbitrary |
| 3313 | UPDATE and DELETE with mapper inheritance configurations. |
| 3314 | |
| 3315 | :param values: a dictionary with attributes names, or alternatively |
| 3316 | mapped attributes or SQL expressions, as keys, and literal |
| 3317 | values or sql expressions as values. If :ref:`parameter-ordered |
| 3318 | mode <tutorial_parameter_ordered_updates>` is desired, the values can |
| 3319 | be passed as a list of 2-tuples; this requires that the |
| 3320 | :paramref:`~sqlalchemy.sql.expression.update.preserve_parameter_order` |
| 3321 | flag is passed to the :paramref:`.Query.update.update_args` dictionary |
| 3322 | as well. |
| 3323 | |
| 3324 | :param synchronize_session: chooses the strategy to update the |
| 3325 | attributes on objects in the session. See the section |
| 3326 | :ref:`orm_expression_update_delete` for a discussion of these |
| 3327 | strategies. |
| 3328 | |
| 3329 | :param update_args: Optional dictionary, if present will be passed |
| 3330 | to the underlying :func:`_expression.update` construct as the ``**kw`` |
| 3331 | for the object. May be used to pass dialect-specific arguments such |
| 3332 | as ``mysql_limit``, as well as other special arguments such as |
| 3333 | :paramref:`~sqlalchemy.sql.expression.update.preserve_parameter_order`. |
| 3334 | |
| 3335 | :return: the count of rows matched as returned by the database&class="cm">#x27;s |
| 3336 | class="st">"row count" feature. |
| 3337 | |
| 3338 | |
| 3339 | .. seealso:: |
| 3340 | |
| 3341 | :ref:`orm_expression_update_delete` |
| 3342 | |
| 3343 | class="st">""" |
| 3344 | |
| 3345 | update_args = update_args or {} |
| 3346 |