Skip to content

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

Instance Properties

  • columns
    List of one or more columns which specify the ordering and count of the inserted values.
  • conflictStrategy
    If not nil, a database-agnostic strategy for resolving conflicts created by violations of applicable constraints.
  • genericConflictStrategy
    The actual conflict resolution strategy serialized by this query. This property is provided to enable easier use of database-specific conflict resolution syntax, as changing conflictStrategy to have the more generic type would be API-breaking.
  • returning
    An optional SQLReturning clause specifying data to return from the inserted rows.
  • table
    The table to which rows are to be added.
  • tableExpressionGroup
    An optional common table expression group.
  • valueQuery
    If not nil, a subquery providing a SELECT statement which generates rows to insert.
  • values
    An array of arrays providing a list of rows to insert as lists of expressions.

Instance Methods

  • serialize(to:)
    Invoked when a request is made to serialize the expression to raw SQL.

Relationships

Conforms To

See Also

Query Expressions

  • SQLAlterEnum
    An expression representing an ALTER TYPE query. Used to add new cases to enumeration types.
  • SQLAlterTable
    An expression representing an ALTER TABLE query. Used to modify the structure of existing tables.
  • SQLCreateEnum
    An expression representing a CREATE TYPE query. Used to create enumeration types.
  • SQLCreateIndex
    An expression representing a CREATE INDEX query. Used to add indexes over columns to an existing table.
  • SQLCreateTable
    An expression representing a CREATE TABLE query. Used to create new tables.
  • SQLCreateTrigger
    An expression representing a CREATE TRIGGER query. Used to create new triggers for actions on a table.
  • SQLDelete
    An expression representing a CREATE TRIGGER query. Used to remove rows from a table.
  • SQLDropEnum
    An expression representing a DROP TYPE query. Used to delete enumeration types.
  • SQLDropIndex
    An expression representing a DROP INDEX query. Used to delete indexes from tables.
  • SQLDropTable
    An expression representing a DROP TABLE query. Used to delete entire tables.
  • SQLDropTrigger
    An expression representing a DROP TRIGGER query. Used to delete triggers.
  • SQLSelect
    An expression representing a SELECT query. Used to retrieve rows and expression results from a database.
  • SQLUnion
    An expression representing two or more SELECT queries joined by UNION clauses. Used to merge the results of multiple queries into a single result set.
  • SQLUpdate
    An expression representing an UPDATE query. Used to modify existing rows in a single table.