final class AddColumn
    implements AlterCommand
    uses Snapshot
Public API: explicitly declared with @visibility public.

ADD [ COLUMN ]: adds a column to the relation.

Mirrors AT_AddColumn with missing_ok for IF NOT EXISTS. The optional COLUMN word changes nothing and is not kept. The expressions of the new column are derived where the relation and the new column are visible. Source: https://www.postgresql.org/docs/17/sql-altertable.html.

Reading an added columndoctest
$statement = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('ALTER TABLE t ADD COLUMN IF NOT EXISTS c int NOT NULL');
    [$statement->statement->commands[0]->column->name->value, $statement->toString()] // => ['c', 'ALTER TABLE t ADD IF NOT EXISTS c INT NOT NULL']

Properties§

public bool $ifNotExists = false

Methods§

public function __construct(public ColumnDefinition $column, public bool $ifNotExists = false)

Parameters

$columnColumnDefinitionThe new column
$ifNotExistsboolWhether IF NOT EXISTS is written
public function deriveClause(Derivation $derivation, Environment $environment): void

Derives the new column.

Parameters

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

Writes ADD and the column.

Parameters

$outOutput
Calls 2

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
Type checks 3
Type declarations 1