MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / update

Method update

lib/sqlalchemy/orm/query.py:3231–3322  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

3229 return result.rowcount
3230
3231 def update(
3232 self,
3233 values: Dict[_DMLColumnArgument, Any],
3234 synchronize_session: SynchronizeSessionArgument = "auto",
3235 update_args: Optional[Dict[Any, Any]] = None,
3236 ) -> int:
3237 r"""Perform an UPDATE with an arbitrary WHERE clause.
3238
3239 Updates rows matched by this query in the database.
3240
3241 E.g.::
3242
3243 sess.query(User).filter(User.age == 25).update(
3244 {User.age: User.age - 10}, synchronize_session=False
3245 )
3246
3247 sess.query(User).filter(User.age == 25).update(
3248 {"age": User.age - 10}, synchronize_session="evaluate"
3249 )
3250
3251 .. warning::
3252
3253 See the section :ref:`orm_expression_update_delete` for important
3254 caveats and warnings, including limitations when using arbitrary
3255 UPDATE and DELETE with mapper inheritance configurations.
3256
3257 :param values: a dictionary with attributes names, or alternatively
3258 mapped attributes or SQL expressions, as keys, and literal
3259 values or sql expressions as values. If :ref:`parameter-ordered
3260 mode <tutorial_parameter_ordered_updates>` is desired, the values can
3261 be passed as a list of 2-tuples; this requires that the
3262 :paramref:`~sqlalchemy.sql.expression.update.preserve_parameter_order`
3263 flag is passed to the :paramref:`.Query.update.update_args` dictionary
3264 as well.
3265
3266 :param synchronize_session: chooses the strategy to update the
3267 attributes on objects in the session. See the section
3268 :ref:`orm_expression_update_delete` for a discussion of these
3269 strategies.
3270
3271 :param update_args: Optional dictionary, if present will be passed
3272 to the underlying :func:`_expression.update` construct as the ``**kw``
3273 for the object. May be used to pass dialect-specific arguments such
3274 as ``mysql_limit``, as well as other special arguments such as
3275 :paramref:`~sqlalchemy.sql.expression.update.preserve_parameter_order`.
3276
3277 :return: the count of rows matched as returned by the database&#x27;s
3278 "row count" feature.
3279
3280
3281 .. seealso::
3282
3283 :ref:`orm_expression_update_delete`
3284
3285 """
3286
3287 update_args = update_args or {}
3288

Callers 15

_setup_for_driverFunction · 0.45
__init__Method · 0.45
create_connect_argsMethod · 0.45
for_update_clauseMethod · 0.45
_on_conflict_targetMethod · 0.45
create_connect_argsMethod · 0.45
create_connect_argsMethod · 0.45
create_connect_argsMethod · 0.45
create_connect_argsMethod · 0.45
MySQLCompilerClass · 0.45
_parse_columnMethod · 0.45

Calls 10

BulkUpdateClass · 0.85
castFunction · 0.85
ordered_valuesMethod · 0.80
with_dialect_optionsMethod · 0.80
after_bulk_updateMethod · 0.80
popMethod · 0.45
valuesMethod · 0.45
executeMethod · 0.45
unionMethod · 0.45
closeMethod · 0.45

Tested by 15

_assert_tableMethod · 0.36
test_update_singleMethod · 0.36
test_update_manyMethod · 0.36
test_updateMethod · 0.36
test_update_returningMethod · 0.36
_resolve_kindMethod · 0.36
_resolve_viewsMethod · 0.36
_resolve_namesMethod · 0.36
test_update_rowcount1Method · 0.36