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

ON CONFLICT [ conflict_target ] DO UPDATE SET ... [ WHERE condition ]: the existing row that conflicts is updated instead.

Mirrors PostgreSQL's OnConflictClause with ONCONFLICT_UPDATE. The assignments and the condition see the target table and, under the name excluded, the row proposed for insertion. PostgreSQL requires a conflict target; its absence is a diagnostic. Source: https://www.postgresql.org/docs/17/sql-insert.html#SQL-ON-CONFLICT.

Reading the assignments of an upsertdoctest
$insert = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('INSERT INTO t VALUES (1) ON CONFLICT (a) DO UPDATE SET a = excluded.a WHERE t.a > 0');
    [count($insert->statement->conflict->assignments), $insert->toString()] // => [1, 'INSERT INTO t VALUES (1) ON CONFLICT (a) DO UPDATE SET a = excluded.a WHERE t.a > 0']
Refusing DO UPDATE without an assignmentdoctest
new \SqlSemantics\Platform\PostgreSql\Statement\Manipulation\Conflict\ConflictDoUpdate(null, []) // throws \SqlSemantics\Platform\PostgreSql\Model\Diagnostic\InvalidConstruction

Properties§

public non-empty-list<Assignment|RowAssignment> $assignments
public Scalar|null $where = null

Methods§

public function __construct(
    public IndexInference|ConstraintInference|null $target,
    list<Assignment|RowAssignment> $assignments,
    public Scalar|null $where = null,
)

Parameters

$targetIndexInference|ConstraintInference|nullThe conflict target
$assignmentslist<Assignment|RowAssignment>The SET items in written order; at least one
$whereScalar|nullThe condition a conflicting row must meet to be updated

Throws

InvalidConstruction When there is no SET item
Calls 4
public function render(Output $out): void

Writes ON CONFLICT, the target, DO UPDATE SET, the assignments and the condition.

Parameters

$outOutput
Calls 1

Test cases 1§

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

Dedicated tests 1

Relations§

Instantiated in 1
Type checks 1
Type declarations 5