classGeneratedWrites
final class GeneratedWrites
Reports a generated column that a data-modifying statement writes with a value other than DEFAULT.
Rule: PG-GENERATED-WRITE-001. A generated column takes only DEFAULT, whatever OVERRIDING clause the statement has. An INSERT, the INSERT action of MERGE included, writes a column of its column list (or, without one, the column at the position of a value) with a value other than DEFAULT unless every row of its VALUES gives DEFAULT there; the rows of a query are never DEFAULT. An UPDATE, the UPDATE action of MERGE and ON CONFLICT DO UPDATE included, writes a column of its SET list with a value other than DEFAULT unless the item, or the field of the row constructor of a multiple-column item, is DEFAULT; a sub-SELECT is never DEFAULT, and assigning a value to a part of the column (a subscript or a field) writes the column. Parentheses around DEFAULT do not change it. The server checks the columns in table order after parse analysis (rewriteTargetListIU, rewriteHandler.c), so the first generated column so written is reported: cannot insert a non-DEFAULT value into column "b" or column "b" can only be updated to DEFAULT, both with the detail Column "b" is a generated column.. A column counts when its slot is a declared generated column of the target; through a view the base column is not followed. An action of CREATE RULE is not checked: the server stores it without rewriting it, and the check applies only when the rule fires; a statement of a routine body (BEGIN ATOMIC) is checked. Source: https://www.postgresql.org/docs/17/ddl-generated-columns.html, https://www.postgresql.org/docs/16/ddl-generated-columns.html, https://github.com/postgres/postgres/blob/REL_17_2/src/backend/rewrite/rewriteHandler.c. Status: Implemented.
Methods§
public function inserted(
VisibleRelation $target,
list<ColumnTarget> $columns,
list<list<Scalar>> $rows,
int|null $width,
Derivation $derivation,
Environment $environment,
): voidReports the first generated column an INSERT writes with a value other than DEFAULT.
Parameters
$target | VisibleRelation | |
$columns | list<ColumnTarget> | The column list; empty to write the columns of the table in order |
$rows | list<list<Scalar>> | The VALUES rows; empty when a query supplies the rows |
$width | int|null | The number of values per row, or null when it is not known |
$derivation | Derivation | |
$environment | Environment | The environment of the statement |
Called from 3
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::rows() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:78
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::select() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:105
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\MergeFacts::clause() packages/sql-semantics-postgres/src/Rules/Manipulation/MergeFacts.php:108
Calls 8
- method-call GeneratedWrites::checked() line 60
- method-call GeneratedWrites::targets() line 63
- function-call
countline 64 - new Assignments line 65
- function-call
array_sliceline 67 - method-call Assignments::requested() line 70
- method-call GeneratedWrites::report() line 76
- class-const ManipulationMisuseRule::GeneratedInsert() line 76
public function updated(
VisibleRelation $target,
list<Assignment|RowAssignment> $assignments,
Derivation $derivation,
Environment $environment,
): voidReports the first generated column a SET list writes with a value other than DEFAULT.
Parameters
$target | VisibleRelation | |
$assignments | list<Assignment|RowAssignment> | |
$derivation | Derivation | |
$environment | Environment | The environment of the SET list |
Called from 1
Calls 7
- method-call GeneratedWrites::checked() line 87
- new Assignments line 90
- method-call Assignments::bare() line 94
- method-call GeneratedWrites::targets() line 95
- method-call Assignments::requested() line 97
- method-call GeneratedWrites::report() line 102
- class-const ManipulationMisuseRule::GeneratedUpdate() line 102
public function checked(Environment $environment): boolTells whether the server rewrites the statement where it is written: not inside an action of CREATE RULE, whose scope holds OLD and NEW of the rule.
Parameters
$environment | Environment |
Returns
boolCalled from 2
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\GeneratedWrites::inserted() packages/sql-semantics-postgres/src/Rules/Manipulation/GeneratedWrites.php:60
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\GeneratedWrites::updated() packages/sql-semantics-postgres/src/Rules/Manipulation/GeneratedWrites.php:87
public function targets(
list<ColumnTarget> $columns,
VisibleRelation $target,
Derivation $derivation,
): list<OutputSlot|null>Answers the slot of the target each listed column writes, whole or in part, or null for a column the target does not show.
Parameters
$columns | list<ColumnTarget> | |
$target | VisibleRelation | |
$derivation | Derivation |
Returns
list<OutputSlot|null>Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\GeneratedWrites::inserted() packages/sql-semantics-postgres/src/Rules/Manipulation/GeneratedWrites.php:63
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\GeneratedWrites::updated() packages/sql-semantics-postgres/src/Rules/Manipulation/GeneratedWrites.php:95
Calls 3
- new Assignments line 130
- function-call
array_mapline 132 - method-call Assignments::find() line 132
public function report(
VisibleRelation $target,
list<OutputSlot> $written,
ManipulationMisuseRule $rule,
Derivation $derivation,
): voidReports the first slot of the target, in table order, that is written and is a generated column.
Parameters
$target | VisibleRelation | |
$written | list<OutputSlot> | |
$rule | ManipulationMisuseRule | |
$derivation | Derivation |
Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\GeneratedWrites::inserted() packages/sql-semantics-postgres/src/Rules/Manipulation/GeneratedWrites.php:76
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\GeneratedWrites::updated() packages/sql-semantics-postgres/src/Rules/Manipulation/GeneratedWrites.php:102
Calls 3
- function-call
in_arrayline 144 - method-call Derivation::report() line 145
- new ManipulationMisuse line 145
Test cases 1§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 1
GeneratedWritesTestcalls
Relations§
Instantiated in 4
- new SqlSemantics\Platform\PostgreSql\Rules\Manipulation\Assignments::assign() packages/sql-semantics-postgres/src/Rules/Manipulation/Assignments.php:172
- new SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::rows() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:78
- new SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::select() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:105
- new SqlSemantics\Platform\PostgreSql\Rules\Manipulation\MergeFacts::clause() packages/sql-semantics-postgres/src/Rules/Manipulation/MergeFacts.php:108
Method calls 4
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\Assignments::assign() packages/sql-semantics-postgres/src/Rules/Manipulation/Assignments.php:172
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::rows() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:78
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\InsertFacts::select() packages/sql-semantics-postgres/src/Rules/Manipulation/InsertFacts.php:105
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\MergeFacts::clause() packages/sql-semantics-postgres/src/Rules/Manipulation/MergeFacts.php:108