MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / with_for_update

Method with_for_update

lib/sqlalchemy/sql/selectable.py:4114–4179  ·  view source on GitHub ↗

Specify a ``FOR UPDATE`` clause for this :class:`_expression.GenerativeSelect`. E.g.:: stmt = select(table).with_for_update(nowait=True) On a database like PostgreSQL or Oracle Database, the above would render a statement like: .. sourcecode::

(
        self,
        *,
        nowait: bool = False,
        read: bool = False,
        of: Optional[_ForUpdateOfArgument] = None,
        skip_locked: bool = False,
        key_share: bool = False,
    )

Source from the content-addressed store, hash-verified

4112
4113 @_generative
4114 def with_for_update(
4115 self,
4116 *,
4117 nowait: bool = False,
4118 read: bool = False,
4119 of: Optional[_ForUpdateOfArgument] = None,
4120 skip_locked: bool = False,
4121 key_share: bool = False,
4122 ) -> Self:
4123 """Specify a ``FOR UPDATE`` clause for this
4124 :class:`_expression.GenerativeSelect`.
4125
4126 E.g.::
4127
4128 stmt = select(table).with_for_update(nowait=True)
4129
4130 On a database like PostgreSQL or Oracle Database, the above would
4131 render a statement like:
4132
4133 .. sourcecode:: sql
4134
4135 SELECT table.a, table.b FROM table FOR UPDATE NOWAIT
4136
4137 on other backends, the ``nowait`` option is ignored and instead
4138 would produce:
4139
4140 .. sourcecode:: sql
4141
4142 SELECT table.a, table.b FROM table FOR UPDATE
4143
4144 When called with no arguments, the statement will render with
4145 the suffix ``FOR UPDATE``. Additional arguments can then be
4146 provided which allow for common database-specific
4147 variants.
4148
4149 :param nowait: boolean; will render ``FOR UPDATE NOWAIT`` on Oracle
4150 Database and PostgreSQL dialects.
4151
4152 :param read: boolean; will render ``LOCK IN SHARE MODE`` on MySQL,
4153 ``FOR SHARE`` on PostgreSQL. On PostgreSQL, when combined with
4154 ``nowait``, will render ``FOR SHARE NOWAIT``.
4155
4156 :param of: SQL expression or list of SQL expression elements,
4157 (typically :class:`_schema.Column` objects or a compatible expression,
4158 for some backends may also be a table expression) which will render
4159 into a ``FOR UPDATE OF`` clause; supported by PostgreSQL, Oracle
4160 Database, some MySQL versions and possibly others. May render as a
4161 table or as a column depending on backend.
4162
4163 :param skip_locked: boolean, will render ``FOR UPDATE SKIP LOCKED`` on
4164 Oracle Database and PostgreSQL dialects or ``FOR SHARE SKIP LOCKED``
4165 if ``read=True`` is also specified.
4166
4167 :param key_share: boolean, will render ``FOR NO KEY UPDATE``,
4168 or if combined with ``read=True`` will render ``FOR KEY SHARE``,
4169 on the PostgreSQL dialect.
4170
4171 """

Callers

nothing calls this directly

Calls 1

ForUpdateArgClass · 0.85

Tested by

no test coverage detected