class documentation

class Insert(StandardInsert):

View In Hierarchy

SQLite-specific implementation of INSERT.

Adds methods for SQLite-specific syntaxes such as ON CONFLICT.

The _sqlite.Insert object is created using the sqlalchemy.dialects.sqlite.insert function.

New in version 1.4.
Method on​_conflict​_do​_nothing Specifies a DO NOTHING action for ON CONFLICT clause.
Method on​_conflict​_do​_update Specifies a DO UPDATE SET action for ON CONFLICT clause.
Class Variable ​_on​_conflict​_exclusive Undocumented
Class Variable inherit​_cache Undocumented
Class Variable stringify​_dialect Undocumented
Instance Variable ​_post​_values​_clause Undocumented
Property excluded Provide the excluded namespace for an ON CONFLICT statement
@_generative
@_on_conflict_exclusive
def on_conflict_do_nothing(self, index_elements=None, index_where=None):
Specifies a DO NOTHING action for ON CONFLICT clause.
Parameters
index​_elementsA sequence consisting of string column names, _schema.Column objects, or other column expression objects that will be used to infer a target index or unique constraint.
index​_whereAdditional WHERE criterion that can be used to infer a conditional target index.
@_generative
@_on_conflict_exclusive
def on_conflict_do_update(self, index_elements=None, index_where=None, set_=None, where=None):
Specifies a DO UPDATE SET action for ON CONFLICT clause.
Parameters
index​_elementsA sequence consisting of string column names, _schema.Column objects, or other column expression objects that will be used to infer a target index or unique constraint.
index​_whereAdditional WHERE criterion that can be used to infer a conditional target index.
set​_

A dictionary or other mapping object where the keys are either names of columns in the target table, or _schema.Column objects or other ORM-mapped columns matching that of the target table, and expressions or literals as values, specifying the SET actions to take.

New in version 1.4: The :paramref:`_sqlite.Insert.on_conflict_do_update.set_` parameter supports _schema.Column objects from the target _schema.Table as keys.

Warning

This dictionary does not take into account Python-specified default UPDATE values or generation functions, e.g. those specified using :paramref:`_schema.Column.onupdate`. These values will not be exercised for an ON CONFLICT style of UPDATE, unless they are manually specified in the :paramref:`.Insert.on_conflict_do_update.set_` dictionary.

whereOptional argument. If present, can be a literal SQL string or an acceptable expression for a WHERE clause that restricts the rows affected by DO UPDATE SET. Rows not meeting the WHERE condition will not be updated (effectively a DO NOTHING for those rows).
_on_conflict_exclusive =

Undocumented

inherit_cache: bool =

Undocumented

stringify_dialect: str =

Undocumented

_post_values_clause =

Undocumented

Provide the excluded namespace for an ON CONFLICT statement

SQLite's ON CONFLICT clause allows reference to the row that would be inserted, known as excluded. This attribute provides all columns in this row to be referenceable.

Tip

The _sqlite.Insert.excluded attribute is an instance of _expression.ColumnCollection, which provides an interface the same as that of the _schema.Table.c collection described at :ref:`metadata_tables_and_columns`. With this collection, ordinary names are accessible like attributes (e.g. stmt.excluded.some_column), but special names and dictionary method names should be accessed using indexed access, such as stmt.excluded["column name"] or stmt.excluded["values"]. See the docstring for _expression.ColumnCollection for further examples.