final class AlterAddColumn
    implements Statement, Relation
    uses Snapshot
Public API: explicitly declared with @visibility public.

A request to add a column at the end of a table.

Rule: SQLITE-ALTER-ADD-COLUMN-001. The resolution of the table is the relation fact of the statement node. The node is the relation occurrence the expressions of the new column definition are derived against: its row shape is the columns of the existing table followed by the new column, which has the declared type SQLite records and is never NULL only when it is declared NOT NULL. Diagnostics, besides those of the table resolution and of the expressions: a view (SQLITE-RELATION-KIND-001), which SQLite refuses before it reads the new column; otherwise a column name the completely known table already has; a PRIMARY KEY or UNIQUE column; a STORED generated column; a NOT NULL column without a default value other than NULL; in a STRICT table a type that is not one of the six standard names. The optional COLUMN keyword is not written. The statement changes no declaration and provides none. Source: https://sqlite.org/lang_altertable.html#alter_table_add_column. Status: Implemented.

Deriving the shape the new column definition seesdoctest
$semantics = new \SqlSemantics\Platform\Sqlite\Semantics();
    $table = $semantics->analyze('CREATE TABLE t (a INTEGER)');
    $alter = $semantics->analyze('ALTER TABLE t ADD COLUMN b TEXT CHECK (b <> a)', [$table]);
    [count($alter->facts->relation($alter->statement)->shape->slots), $alter->toString()] // => [2, 'ALTER TABLE t ADD b TEXT CHECK (b <> a)']

Properties§

public QualifiedName $table

Methods§

public function __construct(public QualifiedName $table, public ColumnDefinition $column)

Parameters

$tableQualifiedNameThe table to change
$columnColumnDefinitionThe definition of the new column
Calls 1
public function deriveStatement(Derivation $derivation): void

Resolves the table, reports what rules the addition out and derives the expressions of the new column.

Parameters

$derivationDerivation
Calls 12
public function deriveRelation(Derivation $derivation, Environment $environment): RelationFact

Derives the row shape of the table with the new column.

Parameters

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

Writes the request.

Parameters

$outOutput
Calls 3

Test cases 5§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 2
Other tests reaching this symbol 3

Relations§

Instantiated in 1