final class Upsert
    implements Node
    uses Snapshot
Public API: explicitly declared with @visibility public.

One ON CONFLICT clause of an INSERT: what to do when a row violates a uniqueness constraint.

A clause without assignments is DO NOTHING; a clause with assignments is DO UPDATE SET, optionally restricted by a predicate. Source: https://sqlite.org/lang_upsert.html.

Reading an upsert clausedoctest
$insert = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('INSERT INTO t VALUES (1) ON CONFLICT (a) DO UPDATE SET a = excluded.a WHERE a < 5');
    [count($insert->statement->upserts[0]->assignments), $insert->statement->upserts[0]->where !== null] // => [1, true]
Refusing a predicate on DO NOTHINGdoctest
new \SqlSemantics\Platform\Sqlite\Statement\Mutation\Upsert(null, [], new \SqlSemantics\Platform\Sqlite\Statement\Expression\Literal\NullLiteral()) // throws \SqlSemantics\Platform\Sqlite\Model\Diagnostic\InvalidConstruction

Properties§

public list<Assignment|RowAssignment> $assignments
public ConflictTarget|null $target = null
public Scalar|null $where = null

Methods§

public function __construct(
    public ConflictTarget|null $target = null,
    list<Assignment|RowAssignment> $assignments = [],
    public Scalar|null $where = null,
)

Parameters

$targetConflictTarget|nullThe constraint the clause reacts to; null for any constraint
$assignmentslist<Assignment|RowAssignment>The assignments of DO UPDATE; none for DO NOTHING
$whereScalar|nullThe predicate of DO UPDATE

Throws

InvalidConstruction When an assignment is of no assignment class
Calls 5
public function render(Output $out): void

Writes the clause.

Parameters

$outOutput
Calls 1

Test cases 5§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 1
Other tests reaching this symbol 4

Relations§

Instantiated in 4
Constant reads 2