classConflictDoUpdate
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.
$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']new \SqlSemantics\Platform\PostgreSql\Statement\Manipulation\Conflict\ConflictDoUpdate(null, []) // throws \SqlSemantics\Platform\PostgreSql\Model\Diagnostic\InvalidConstructionProperties§
public non-empty-list<Assignment|RowAssignment> $assignmentspublic IndexInference|ConstraintInference|null $targetpublic Scalar|null $where = nullMethods§
public function __construct(
public IndexInference|ConstraintInference|null $target,
list<Assignment|RowAssignment> $assignments,
public Scalar|null $where = null,
)Parameters
$target | IndexInference|ConstraintInference|null | The conflict target |
$assignments | list<Assignment|RowAssignment> | The SET items in written order; at least one |
$where | Scalar|null | The condition a conflicting row must meet to be updated |
Throws
InvalidConstruction When there is no SET itemCalls 4
- method-call ClosedList::of() line 50
- new ClosedList line 50
- class-const Assignment::class() line 50
- class-const RowAssignment::class() line 50
public function render(Output $out): voidWrites ON CONFLICT, the target, DO UPDATE SET, the assignments and the condition.
Parameters
$out | Output |
Calls 1
- method-call Output::keyword() line 58
Test cases 1§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 1
ConflictDoUpdateTestcalls
Relations§
Instantiated in 1
Type checks 1
Type declarations 5
- type SqlSemantics\Platform\PostgreSql\Lowering\Manipulation\InsertRule packages/sql-semantics-postgres/src/Lowering/Manipulation/InsertRule.php:182
- type SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:162
- type SqlSemantics\Platform\PostgreSql\Statement\Manipulation\InsertDefaults packages/sql-semantics-postgres/src/Statement/Manipulation/InsertDefaults.php:53
- type SqlSemantics\Platform\PostgreSql\Statement\Manipulation\InsertRows packages/sql-semantics-postgres/src/Statement/Manipulation/InsertRows.php:68
- type SqlSemantics\Platform\PostgreSql\Statement\Manipulation\InsertSelect packages/sql-semantics-postgres/src/Statement/Manipulation/InsertSelect.php:72