classInsertFacts
final class InsertFacts
Derives the facts of an INSERT statement.
Rule: PG-INSERT-001. The common tables and the target follow PG-MODIFICATION-SCOPE-001; the columns follow PG-ASSIGNMENT-001. The VALUES rows and the query see the common tables, not the target. Every VALUES row must have as many values as the first. With a column list, each row must supply one value per column; without one, at most one value per column of the table, the rest taking their defaults; more or fewer are reported when both counts are known. Each value of a VALUES row is assigned to its column on its own (PG-ASSIGNMENT-CAST-001); an output column of the query is checked the same way unless it is of a string type, which a string constant of the query also has. The conflict target sees the target only; DO UPDATE and its condition see the target and, under the name excluded, the row proposed for insertion, each qualifying the same columns, so an unqualified column of both is ambiguous; DO UPDATE without a conflict target is reported. RETURNING sees the target. A generated column takes DEFAULT only (PG-GENERATED-WRITE-001). Source: https://www.postgresql.org/docs/17/sql-insert.html, https://www.postgresql.org/docs/17/sql-insert.html#SQL-ON-CONFLICT. Status: Implemented.
Methods§
public function rows(InsertRows $insert, Derivation $derivation, Environment $outer): QueryFactDerives an INSERT of VALUES rows and answers its rows.
Parameters
$insert | InsertRows | |
$derivation | Derivation | |
$outer | Environment |
Returns
Called from 1
Calls 19
- new ModificationScope line 57
- method-call ModificationScope::open() line 58
- method-call InsertFacts::columns() line 59
- function-call
countline 62 - new Assignments line 63
- method-call Derivation::report() line 66
- new ArityMismatch line 66
- class-const ArityRule::ValuesRows() line 66
- method-call Derivation::scalar() line 69
- method-call Assignments::value() line 70
- method-call Assignments::requested() line 71
- method-call InsertFacts::arity() line 77
- method-call GeneratedWrites::inserted() line 78
- new GeneratedWrites line 78
- function-call
array_mapline 78 - method-call InsertFacts::conflict() line 79
- method-call Placement::values() line 80
- new Placement line 80
- method-call ModificationScope::returning() line 82
public function select(
InsertSelect $insert,
Derivation $derivation,
Environment $outer,
): QueryFactDerives an INSERT of the rows of a query and answers its rows.
Parameters
$insert | InsertSelect | |
$derivation | Derivation | |
$outer | Environment |
Returns
Called from 1
Calls 16
- new ModificationScope line 90
- method-call ModificationScope::open() line 91
- method-call InsertFacts::columns() line 92
- method-call Derivation::query() line 93
- new Categories line 96
- method-call Categories::builtin() line 98
- method-call Categories::textual() line 99
- method-call Assignments::value() line 100
- new Assignments line 100
- method-call InsertFacts::arity() line 103
- method-call GeneratedWrites::inserted() line 105
- new GeneratedWrites line 105
- method-call InsertFacts::conflict() line 106
- method-call Placement::values() line 107
- new Placement line 107
- method-call ModificationScope::returning() line 109
public function defaults(
InsertDefaults $insert,
Derivation $derivation,
Environment $outer,
): QueryFactDerives an INSERT of the column defaults and answers its rows.
Parameters
$insert | InsertDefaults | |
$derivation | Derivation | |
$outer | Environment |
Returns
Called from 1
Calls 6
- new ModificationScope line 117
- method-call ModificationScope::open() line 118
- method-call InsertFacts::conflict() line 119
- method-call Placement::values() line 120
- new Placement line 120
- method-call ModificationScope::returning() line 122
public function columns(
list<ColumnTarget> $columns,
VisibleRelation $target,
Derivation $derivation,
Environment $base,
): list<OutputSlot|null>Derives the column list and answers the slot each value is assigned to: the columns listed, or every column of the table.
Parameters
$columns | list<ColumnTarget> | |
$target | VisibleRelation | |
$derivation | Derivation | |
$base | Environment |
Returns
list<OutputSlot|null>Called from 3
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::rows() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:59
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::select() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:92
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\MergeFacts::clause() packages/sql-semantics-postgres/src/Rules/Manipulation/MergeFacts.php:98
Calls 3
- method-call Assignments::columns() line 138
- new Assignments line 138
- class-const ManipulationMisuseRule::RepeatedInsertColumn() line 138
public function arity(
list<ColumnTarget> $columns,
VisibleRelation $target,
int $values,
Derivation $derivation,
): voidReports a number of values per row that does not fit the columns.
Parameters
$columns | list<ColumnTarget> | |
$target | VisibleRelation | |
$values | int | |
$derivation | Derivation |
Called from 3
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::rows() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:77
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::select() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:103
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\MergeFacts::clause() packages/sql-semantics-postgres/src/Rules/Manipulation/MergeFacts.php:107
Calls 5
- function-call
countline 148 - method-call Derivation::report() line 150
- new ManipulationMisuse line 150
- class-const ManipulationMisuseRule::MoreExpressions() line 150
- class-const ManipulationMisuseRule::MoreTargetColumns() line 153
public function conflict(
ConflictDoNothing|ConflictDoUpdate|null $conflict,
VisibleRelation $target,
Derivation $derivation,
Environment $base,
): list<DefaultRequest>Derives the ON CONFLICT clause and answers the DEFAULT values it admits.
Parameters
$conflict | ConflictDoNothing|ConflictDoUpdate|null | |
$target | VisibleRelation | |
$derivation | Derivation | |
$base | Environment |
Returns
list<DefaultRequest>Called from 3
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::rows() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:79
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::select() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:106
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::defaults() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:119
Calls 10
- new Environment line 168
- method-call Derivation::scalar() line 173
- method-call Derivation::report() line 180
- new ManipulationMisuse line 180
- class-const ManipulationMisuseRule::ConflictUpdateWithoutTarget() line 180
- new VisibleRelation line 182
- new Name line 182
- new Assignments line 184
- method-call Assignments::assign() line 185
- method-call Assignments::defaults() line 190
Test cases 1§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 1
InsertFactsTestcalls
Relations§
Instantiated in 4
- new SqlSemantics\Platform\PostgreSql\Rules\Manipulation\MergeFacts::clause() packages/sql-semantics-postgres/src/Rules/Manipulation/MergeFacts.php:97
- new SqlSemantics\Platform\PostgreSql\Statement\Manipulation\InsertDefaults::deriveQuery() packages/sql-semantics-postgres/src/Statement/Manipulation/InsertDefaults.php:89
- new SqlSemantics\Platform\PostgreSql\Statement\Manipulation\InsertRows::deriveQuery() packages/sql-semantics-postgres/src/Statement/Manipulation/InsertRows.php:105
- new SqlSemantics\Platform\PostgreSql\Statement\Manipulation\InsertSelect::deriveQuery() packages/sql-semantics-postgres/src/Statement/Manipulation/InsertSelect.php:110
Method calls 5
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\MergeFacts::clause() packages/sql-semantics-postgres/src/Rules/Manipulation/MergeFacts.php:98
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\MergeFacts::clause() packages/sql-semantics-postgres/src/Rules/Manipulation/MergeFacts.php:107
- method-call SqlSemantics\Platform\PostgreSql\Statement\Manipulation\InsertDefaults::deriveQuery() packages/sql-semantics-postgres/src/Statement/Manipulation/InsertDefaults.php:89
- method-call SqlSemantics\Platform\PostgreSql\Statement\Manipulation\InsertRows::deriveQuery() packages/sql-semantics-postgres/src/Statement/Manipulation/InsertRows.php:105
- method-call SqlSemantics\Platform\PostgreSql\Statement\Manipulation\InsertSelect::deriveQuery() packages/sql-semantics-postgres/src/Statement/Manipulation/InsertSelect.php:110