Structure
SQLInsert
An expression representing an
INSERT query. Used to add new rows to a table.struct SQLInsert
Overview
INSERT INTO "table"
("id", "column1", "column2")
VALUES
(DEFAULT, 'a', 'b'),
(DEFAULT, 'c', 'd')
ON CONFLICT DO NOTHING
RETURNING "id";
INSERT INTO "table"
("id", "column1", "column2")
SELECT
NULL as "id",
"column1",
"column2"
FROM "other_table"
ON CONFLICT DO UPDATE SET "column1"="excluded"."column1", "column2"="excluded"."column2"
RETURNING "id";
See SQLInsertBuilder.
Topics
Initializers
init(table: any SQLExpression)Create a new row insertion query.
Instance Properties
var columns: [any SQLExpression]List of one or more columns which specify the ordering and count of the inserted values.var conflictStrategy: SQLConflictResolutionStrategy?If notnil, a database-agnostic strategy for resolving conflicts created by violations of applicable constraints.var genericConflictStrategy: (any SQLExpression)?The actual conflict resolution strategy serialized by this query. This property is provided to enable easier use of database-specific conflict resolution syntax, as changingconflictStrategyto have the more generic type would be API-breaking.var returning: SQLReturning?An optionalSQLReturningclause specifying data to return from the inserted rows.var table: any SQLExpressionThe table to which rows are to be added.var tableExpressionGroup: SQLCommonTableExpressionGroup?An optional common table expression group.var valueQuery: (any SQLExpression)?If notnil, a subquery providing aSELECTstatement which generates rows to insert.var values: [[any SQLExpression]]An array of arrays providing a list of rows to insert as lists of expressions.
Instance Methods
func serialize(to: inout SQLSerializer)Invoked when a request is made to serialize the expression to raw SQL.
Relationships
Conforms To
SQLExpressionSwift.SendableSwift.SendableMetatype
See Also
Query Expressions
struct SQLAlterEnumAn expression representing anALTER TYPEquery. Used to add new cases to enumeration types.struct SQLAlterTableAn expression representing anALTER TABLEquery. Used to modify the structure of existing tables.struct SQLCreateEnumAn expression representing aCREATE TYPEquery. Used to create enumeration types.struct SQLCreateIndexAn expression representing aCREATE INDEXquery. Used to add indexes over columns to an existing table.struct SQLCreateTableAn expression representing aCREATE TABLEquery. Used to create new tables.struct SQLCreateTriggerAn expression representing aCREATE TRIGGERquery. Used to create new triggers for actions on a table.struct SQLDeleteAn expression representing aCREATE TRIGGERquery. Used to remove rows from a table.struct SQLDropEnumAn expression representing aDROP TYPEquery. Used to delete enumeration types.struct SQLDropIndexAn expression representing aDROP INDEXquery. Used to delete indexes from tables.struct SQLDropTableAn expression representing aDROP TABLEquery. Used to delete entire tables.struct SQLDropTriggerAn expression representing aDROP TRIGGERquery. Used to delete triggers.struct SQLSelectAn expression representing aSELECTquery. Used to retrieve rows and expression results from a database.struct SQLUnionAn expression representing two or moreSELECTqueries joined byUNIONclauses. Used to merge the results of multiple queries into a single result set.struct SQLUpdateAn expression representing anUPDATEquery. Used to modify existing rows in a single table.