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

One WHEN clause of MERGE: the rows it applies to, an optional condition and the action.

Mirrors PostgreSQL's MergeWhenClause. A clause for rows with a target row updates, deletes or skips; a clause for source rows without target row inserts or skips. Source: https://www.postgresql.org/docs/17/sql-merge.html.

Reading the condition of a WHEN clausedoctest
$merge = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('MERGE INTO t USING u ON t.a = u.a WHEN MATCHED AND u.c THEN DELETE');
    $merge->statement->clauses[0]->condition !== null // => true
Refusing an insert for rows that have a target rowdoctest
new \SqlSemantics\Platform\PostgreSql\Statement\Manipulation\Merge\MergeWhen(\SqlSemantics\Platform\PostgreSql\Statement\Manipulation\Merge\MergeMatch::Matched, null, new \SqlSemantics\Platform\PostgreSql\Statement\Manipulation\Merge\MergeInsertDefaults()) // throws \SqlSemantics\Platform\PostgreSql\Model\Diagnostic\InvalidConstruction

Properties§

public MergeMatch $match
public Scalar|null $condition

Methods§

public function __construct(
    public MergeMatch $match,
    public Scalar|null $condition,
    public MergeUpdate|MergeDelete|MergeInsert|MergeInsertDefaults|MergeNothing $action,
)

Parameters

$matchMergeMatchThe rows the clause applies to
$conditionScalar|nullThe condition written after AND
$actionMergeUpdate|MergeDelete|MergeInsert|MergeInsertDefaults|MergeNothingThe action

Throws

InvalidConstruction When the action does not fit the rows
Calls 2
public function render(Output $out): void

Writes WHEN, the rows, the condition, THEN and the action.

Parameters

$outOutput
Calls 4

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
Constant reads 1
Type declarations 2