final class Generated
    implements Constraint
    uses Snapshot
Public API: explicitly declared with @visibility public.

A GENERATED ... AS ( expression ) STORED column constraint: the column always holds the value of an expression of the other columns.

Mirrors CONSTR_GENERATED with raw_expr. The expression is derived where the columns of the table are visible. A generated column can be NULL. The server requires GENERATED ALWAYS: "for a generated column, GENERATED

  • ALWAYS must be specified" is a diagnostic, and so is an expression that

uses another generated column (PG-GENERATED-COLUMN-001). Source: https://www.postgresql.org/docs/17/sql-createtable.html, https://www.postgresql.org/docs/17/ddl-generated-columns.html.

A generated column refers to other columnsdoctest
$create = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('CREATE TABLE t (a int, b int GENERATED ALWAYS AS (a * 2) STORED)');
    $generated = $create->statement->definition->elements[1]->qualifiers[0];
    $create->facts->scalar($generated->expression->left)->resolution->slot->column === $create->declarations()[0]->columns[0] // => true

Properties§

public Scalar $expression
public Name|null $name = null

Methods§

public function __construct(
    public GeneratedWhen $when,
    public Scalar $expression,
    public Name|null $name = null,
)

Parameters

$whenGeneratedWhenWhen the column takes the generated value
$expressionScalarThe generation expression
$nameName|nullThe constraint name
public function kind(): ConstraintKind

Answers the kind of the constraint.

Calls 1
public function deriveClause(Derivation $derivation, Environment $environment): void

Derives the expression against the table and reports GENERATED BY DEFAULT and a generated column the expression uses.

Parameters

$derivationDerivation
$environmentEnvironment
Calls 7
public function render(Output $out): void

Writes the constraint.

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 7
Type checks 2