MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / on_duplicate_key_update

Method on_duplicate_key_update

lib/sqlalchemy/dialects/mysql/dml.py:163–219  ·  view source on GitHub ↗

r""" Specifies the ON DUPLICATE KEY UPDATE clause. :param \**kw: Column keys linked to UPDATE values. The values may be any SQL expression or supported literal Python values. .. warning:: This dictionary does **not** take into account Python-s

(self, *args: _UpdateArg, **kw: Any)

Source from the content-addressed store, hash-verified

161 },
162 )
163 def on_duplicate_key_update(self, *args: _UpdateArg, **kw: Any) -> Self:
164 r"""
165 Specifies the ON DUPLICATE KEY UPDATE clause.
166
167 :param \**kw: Column keys linked to UPDATE values. The
168 values may be any SQL expression or supported literal Python
169 values.
170
171 .. warning:: This dictionary does **not** take into account
172 Python-specified default UPDATE values or generation functions,
173 e.g. those specified using :paramref:`_schema.Column.onupdate`.
174 These values will not be exercised for an ON DUPLICATE KEY UPDATE
175 style of UPDATE, unless values are manually specified here.
176
177 :param \*args: As an alternative to passing key/value parameters,
178 a dictionary or list of 2-tuples can be passed as a single positional
179 argument.
180
181 Passing a single dictionary is equivalent to the keyword argument
182 form::
183
184 insert().on_duplicate_key_update({"name": "some name"})
185
186 Passing a list of 2-tuples indicates that the parameter assignments
187 in the UPDATE clause should be ordered as sent, in a manner similar
188 to that described for the :class:`_expression.Update`
189 construct overall
190 in :ref:`tutorial_parameter_ordered_updates`::
191
192 insert().on_duplicate_key_update(
193 [
194 ("name", "some name"),
195 ("value", "some value"),
196 ]
197 )
198
199 .. seealso::
200
201 :ref:`mysql_insert_on_duplicate_key_update`
202
203 """
204 if args and kw:
205 raise exc.ArgumentError(
206 "Can't pass kwargs and positional arguments simultaneously"
207 )
208
209 if args:
210 if len(args) > 1:
211 raise exc.ArgumentError(
212 "Only a single dictionary or list of tuples "
213 "is accepted positionally."
214 )
215 values = args[0]
216 else:
217 values = kw
218
219 return self.ext(OnDuplicateClause(self.inserted_alias, values))
220

Calls 2

OnDuplicateClauseClass · 0.85
extMethod · 0.45