classAddColumn
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.
$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 ColumnDefinition $columnpublic bool $ifNotExists = falseMethods§
public function __construct(public ColumnDefinition $column, public bool $ifNotExists = false)Parameters
$column | ColumnDefinition | The new column |
$ifNotExists | bool | Whether IF NOT EXISTS is written |
public function deriveClause(Derivation $derivation, Environment $environment): voidDerives the new column.
Parameters
$derivation | Derivation | |
$environment | Environment |
Calls 1
- method-call ColumnDefinition::deriveClause() line 43
public function render(Output $out): voidWrites ADD and the column.
Parameters
$out | Output |
Calls 2
- method-call Output::keyword() line 51
- method-call Output::node() line 55
Test cases 1§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 1
AddColumnTestcalls
Relations§
Instantiated in 4
- new SqlSemantics\Platform\PostgreSql\Lowering\Table\AlterCommandRule::relation() packages/sql-semantics-postgres/src/Lowering/Table/AlterCommandRule.php:180
- new SqlSemantics\Platform\PostgreSql\Lowering\Table\AlterCommandRule::relation() packages/sql-semantics-postgres/src/Lowering/Table/AlterCommandRule.php:181
- new SqlSemantics\Platform\PostgreSql\Lowering\Table\AlterCommandRule::relation() packages/sql-semantics-postgres/src/Lowering/Table/AlterCommandRule.php:182
- new SqlSemantics\Platform\PostgreSql\Lowering\Table\AlterCommandRule::relation() packages/sql-semantics-postgres/src/Lowering/Table/AlterCommandRule.php:183
Type checks 3
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Table\Command\AlterKinds::foreign() packages/sql-semantics-postgres/src/Rules/Table/Command/AlterKinds.php:112
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Table\Command\AlterKinds::other() packages/sql-semantics-postgres/src/Rules/Table/Command/AlterKinds.php:155
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Table\Command\Alterations::derive() packages/sql-semantics-postgres/src/Rules/Table/Command/Alterations.php:83