class Insert(StandardInsert):
PostgreSQL-specific implementation of INSERT.
Adds methods for PG-specific syntaxes such as ON CONFLICT.
The _postgresql.Insert
object is created using the
sqlalchemy.dialects.postgresql.insert
function.
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 |
Specifies a DO NOTHING action for ON CONFLICT clause.
The constraint and index_elements arguments are optional, but only one of these can be specified.
See Also
Parameters | |
constraint | The name of a unique or exclusion constraint on the table, or the constraint object itself if it has a .name attribute. |
index_elements | A sequence consisting of string column names, _schema.Column
objects, or other column expression objects that will be used
to infer a target index. |
index_where | Additional WHERE criterion that can be used to infer a conditional target index.
New in version 1.1.
|
Specifies a DO UPDATE SET action for ON CONFLICT clause.
Either the constraint or index_elements argument is required, but only one of these can be specified.
See Also
Parameters | |
constraint | The name of a unique or exclusion constraint on the table, or the constraint object itself if it has a .name attribute. |
index_elements | A sequence consisting of string column names, _schema.Column
objects, or other column expression objects that will be used
to infer a target index. |
index_where | Additional 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
New in version 1.4: The
:paramref:`_postgresql.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. |
where | Optional 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).
New in version 1.1.
|
Provide the excluded namespace for an ON CONFLICT statement
PG'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 _postgresql.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.
See Also
:ref:`postgresql_insert_on_conflict` - example of how
to use _expression.Insert.excluded