final class GeneratedWrites
Restricted visibility: declared "@visibility SqlSemantics\Platform\PostgreSql". Code outside that scope must not name this declaration.

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,
): void

Reports the first generated column an INSERT writes with a value other than DEFAULT.

Parameters

$targetVisibleRelation
$columnslist<ColumnTarget>The column list; empty to write the columns of the table in order
$rowslist<list<Scalar>>The VALUES rows; empty when a query supplies the rows
$widthint|nullThe number of values per row, or null when it is not known
$derivationDerivation
$environmentEnvironmentThe environment of the statement
Called from 3
Calls 8
public function updated(
    VisibleRelation $target,
    list<Assignment|RowAssignment> $assignments,
    Derivation $derivation,
    Environment $environment,
): void

Reports the first generated column a SET list writes with a value other than DEFAULT.

Parameters

$targetVisibleRelation
$assignmentslist<Assignment|RowAssignment>
$derivationDerivation
$environmentEnvironmentThe environment of the SET list
Called from 1
Calls 7
public function checked(Environment $environment): bool

Tells 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

$environmentEnvironment

Returns

bool
Called from 2
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

$columnslist<ColumnTarget>
$targetVisibleRelation
$derivationDerivation

Returns

list<OutputSlot|null>
Called from 2
Calls 3

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 4
Method calls 4