classAssignments
final class Assignments
Derives the columns an INSERT column list or a SET list writes, and the values assigned to them.
Rule: PG-ASSIGNMENT-001. A written name is a column of the target table, never a qualifier; a name the table certainly lacks is reported, a system column cannot be written, and a step .* is reported. A column written whole may not be written again, whole or in part, in the same list; parts of one column (different subscripts or fields) may. The subscripts of the steps see the environment of the values. A value is derived in the environment of the clause and must convert to the column type (PG-ASSIGNMENT-CAST-001) when the whole column is written; DEFAULT takes the column default, also in parentheses, which the grammar drops. A multiple-column item takes its values from a row constructor, whose fields may be DEFAULT, or from a scalar subquery, with as many values as columns; any other source is reported. A generated column takes DEFAULT only (PG-GENERATED-WRITE-001). Termination: one pass over the items. Source: https://www.postgresql.org/docs/17/sql-insert.html, https://www.postgresql.org/docs/17/sql-update.html. Status: Implemented.
Methods§
public function columns(
list<ColumnTarget> $columns,
VisibleRelation $target,
Derivation $derivation,
Environment $environment,
ManipulationMisuseRule $repeated,
): list<OutputSlot|null>Derives a list of written columns and answers, per column, the slot written whole, or null when only a part is written or the column is not known.
Parameters
$columns | list<ColumnTarget> | |
$target | VisibleRelation | |
$derivation | Derivation | |
$environment | Environment | |
$repeated | ManipulationMisuseRule |
Returns
list<OutputSlot|null>Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\Assignments::assign() packages/sql-semantics-postgres/src/Rules/Manipulation/Assignments.php:161
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::columns() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:138
Calls 4
- method-call Derivation::report() line 68
- new ManipulationMisuse line 68
- class-const ManipulationMisuseRule::RowExpansion() line 68
- method-call Assignments::slot() line 80
public function slot(
ColumnTarget $column,
VisibleRelation $target,
Derivation $derivation,
): ?OutputSlotFinds the slot of the target a column name writes, reporting a name the target certainly lacks and a system column.
Parameters
$column | ColumnTarget | |
$target | VisibleRelation | |
$derivation | Derivation |
Returns
Called from 1
Calls 5
- method-call Assignments::find() line 93
- method-call Derivation::report() line 100
- new ManipulationMisuse line 100
- class-const ManipulationMisuseRule::SystemColumnAssignment() line 100
- class-const ManipulationMisuseRule::UnknownTargetColumn() line 107
public function find(
ColumnTarget $column,
VisibleRelation $target,
Derivation $derivation,
): ?OutputSlotFinds the slot of the target a column name writes, or null when the target shows no such column.
Parameters
$column | ColumnTarget | |
$target | VisibleRelation | |
$derivation | Derivation |
Returns
Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\Assignments::slot() packages/sql-semantics-postgres/src/Rules/Manipulation/Assignments.php:93
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\GeneratedWrites::targets() packages/sql-semantics-postgres/src/Rules/Manipulation/GeneratedWrites.php:132
Answers an expression without the parentheses around it.
Parameters
$value | Scalar |
Returns
Test cases 1
Called from 4
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\Assignments::requested() packages/sql-semantics-postgres/src/Rules/Manipulation/Assignments.php:145
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\Assignments::row() packages/sql-semantics-postgres/src/Rules/Manipulation/Assignments.php:183
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\Assignments::defaults() packages/sql-semantics-postgres/src/Rules/Manipulation/Assignments.php:258
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\GeneratedWrites::updated() packages/sql-semantics-postgres/src/Rules/Manipulation/GeneratedWrites.php:94
public function requested(?Scalar $value): ?DefaultRequestAnswers the DEFAULT a value is, in parentheses or not, or null when it is another value.
Parameters
$value | ?Scalar |
Returns
Called from 7
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\Assignments::types() packages/sql-semantics-postgres/src/Rules/Manipulation/Assignments.php:230
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\Assignments::value() packages/sql-semantics-postgres/src/Rules/Manipulation/Assignments.php:242
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\Assignments::defaults() packages/sql-semantics-postgres/src/Rules/Manipulation/Assignments.php:261
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\GeneratedWrites::inserted() packages/sql-semantics-postgres/src/Rules/Manipulation/GeneratedWrites.php:70
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\GeneratedWrites::updated() packages/sql-semantics-postgres/src/Rules/Manipulation/GeneratedWrites.php:97
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::rows() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:71
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\MergeFacts::clause() packages/sql-semantics-postgres/src/Rules/Manipulation/MergeFacts.php:102
Calls 1
- method-call Assignments::bare() line 145
public function assign(
list<Assignment|RowAssignment> $assignments,
VisibleRelation $target,
Derivation $derivation,
Environment $environment,
): voidDerives the items of a SET list.
Parameters
$assignments | list<Assignment|RowAssignment> | |
$target | VisibleRelation | |
$derivation | Derivation | |
$environment | Environment |
Called from 3
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\ChangeFacts::update() packages/sql-semantics-postgres/src/Rules/Manipulation/ChangeFacts.php:39
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::conflict() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:185
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\MergeFacts::clause() packages/sql-semantics-postgres/src/Rules/Manipulation/MergeFacts.php:90
Calls 10
- function-call
array_pushline 159 - method-call Assignments::columns() line 161
- class-const ManipulationMisuseRule::RepeatedAssignment() line 161
- method-call Assignments::value() line 165
- method-call Derivation::scalar() line 165
- method-call Assignments::row() line 169
- function-call
array_sliceline 169 - function-call
countline 169 - method-call GeneratedWrites::updated() line 172
- new GeneratedWrites line 172
public function row(
RowAssignment $assignment,
list<OutputSlot|null> $slots,
Derivation $derivation,
Environment $environment,
): voidDerives the source of a multiple-column item and checks it against its columns.
Parameters
$assignment | RowAssignment | |
$slots | list<OutputSlot|null> | |
$derivation | Derivation | |
$environment | Environment |
Called from 1
Calls 9
- method-call Derivation::scalar() line 182
- method-call Assignments::bare() line 183
- method-call Derivation::report() line 185
- new ManipulationMisuse line 185
- class-const ManipulationMisuseRule::MultipleAssignmentSource() line 185
- method-call Assignments::types() line 189
- function-call
countline 193 - class-const ManipulationMisuseRule::MultipleAssignmentArity() line 198
- method-call Assignments::value() line 204
public function types(
RowConstructor|ScalarSubquery $source,
TypeFact $type,
): list<TypeFact|null>|nullAnswers the types of the values a multiple-column source supplies, null for one not to check, or null when they are not known.
A field of a row constructor that is DEFAULT, or whose type the row reports as text (as it does for a string constant), is not checked. A subquery of several columns yields an anonymous record of them; a subquery of one column yields its value.
Parameters
$source | RowConstructor|ScalarSubquery | |
$type | TypeFact |
Returns
list<TypeFact|null>|nullCalled from 1
Calls 2
- method-call Assignments::requested() line 230
- class-const Builtin::Text() line 230
public function value(
?OutputSlot $slot,
?Scalar $value,
TypeFact $type,
Derivation $derivation,
): voidChecks a value assigned to a whole column; DEFAULT and an unknown column are not checked.
Parameters
$slot | ?OutputSlot | |
$value | ?Scalar | |
$type | TypeFact | |
$derivation | Derivation |
Called from 5
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\Assignments::assign() packages/sql-semantics-postgres/src/Rules/Manipulation/Assignments.php:165
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\Assignments::row() packages/sql-semantics-postgres/src/Rules/Manipulation/Assignments.php:204
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::rows() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:70
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::select() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:100
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\MergeFacts::clause() packages/sql-semantics-postgres/src/Rules/Manipulation/MergeFacts.php:101
Calls 3
- method-call Assignments::requested() line 242
- method-call AssignmentCasts::check() line 243
- new AssignmentCasts line 243
public function defaults(list<Assignment|RowAssignment> $assignments): list<DefaultRequest>Answers the DEFAULT values a SET list may hold: the values of the items, and the fields of the row constructors of multiple-column items, in parentheses or not.
Parameters
$assignments | list<Assignment|RowAssignment> |
Returns
list<DefaultRequest>Called from 3
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\ChangeFacts::update() packages/sql-semantics-postgres/src/Rules/Manipulation/ChangeFacts.php:41
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::conflict() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:190
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\MergeFacts::clause() packages/sql-semantics-postgres/src/Rules/Manipulation/MergeFacts.php:92
Calls 2
- method-call Assignments::bare() line 258
- method-call Assignments::requested() line 261
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 9
- new SqlSemantics\Platform\PostgreSql\Rules\Manipulation\ChangeFacts::update() packages/sql-semantics-postgres/src/Rules/Manipulation/ChangeFacts.php:38
- new SqlSemantics\Platform\PostgreSql\Rules\Manipulation\GeneratedWrites::inserted() packages/sql-semantics-postgres/src/Rules/Manipulation/GeneratedWrites.php:65
- new SqlSemantics\Platform\PostgreSql\Rules\Manipulation\GeneratedWrites::updated() packages/sql-semantics-postgres/src/Rules/Manipulation/GeneratedWrites.php:90
- new SqlSemantics\Platform\PostgreSql\Rules\Manipulation\GeneratedWrites::targets() packages/sql-semantics-postgres/src/Rules/Manipulation/GeneratedWrites.php:130
- new SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::rows() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:63
- new SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::select() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:100
- new SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::columns() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:138
- new SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::conflict() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:184
- new SqlSemantics\Platform\PostgreSql\Rules\Manipulation\MergeFacts::clause() packages/sql-semantics-postgres/src/Rules/Manipulation/MergeFacts.php:88
Method calls 16
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\ChangeFacts::update() packages/sql-semantics-postgres/src/Rules/Manipulation/ChangeFacts.php:39
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\ChangeFacts::update() packages/sql-semantics-postgres/src/Rules/Manipulation/ChangeFacts.php:41
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\GeneratedWrites::inserted() packages/sql-semantics-postgres/src/Rules/Manipulation/GeneratedWrites.php:70
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\GeneratedWrites::updated() packages/sql-semantics-postgres/src/Rules/Manipulation/GeneratedWrites.php:94
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\GeneratedWrites::updated() packages/sql-semantics-postgres/src/Rules/Manipulation/GeneratedWrites.php:97
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\GeneratedWrites::targets() packages/sql-semantics-postgres/src/Rules/Manipulation/GeneratedWrites.php:132
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::rows() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:70
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::rows() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:71
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::select() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:100
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::columns() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:138
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::conflict() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:185
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::conflict() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:190
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\MergeFacts::clause() packages/sql-semantics-postgres/src/Rules/Manipulation/MergeFacts.php:90
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\MergeFacts::clause() packages/sql-semantics-postgres/src/Rules/Manipulation/MergeFacts.php:92
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\MergeFacts::clause() packages/sql-semantics-postgres/src/Rules/Manipulation/MergeFacts.php:101
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\MergeFacts::clause() packages/sql-semantics-postgres/src/Rules/Manipulation/MergeFacts.php:102