classAlterTable
final class AlterTable
implements Statement, Relation
uses Snapshot
Public API: explicitly declared with
@visibility public.A request to change a table, an index, a sequence, a view, a materialized view or a foreign table.
Mirrors PostgreSQL's AlterTableStmt (relation, cmds, objtype, missing_ok). The relation is resolved (PG-TABLE-TARGET-001) and is the relation fact of the statement; the actions are derived against it (PG-ALTER-TABLE-001). The statement changes no declaration. ONLY is written only for tables and foreign tables; a partition action stands alone. Source: https://www.postgresql.org/docs/17/sql-altertable.html.
$statement = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('ALTER TABLE IF EXISTS ONLY t ADD c int CHECK (c > a), ALTER b DROP NOT NULL');
$statement->facts->relation($statement->statement)->table::class // => 'SqlSemantics\\Platform\\PostgreSql\\Model\\Statement\\Reference\\Table\\UndeclaredTable'Properties§
public non-empty-list<AlterCommand> $commandspublic AlterTarget $targetpublic RelationReference $relationpublic bool $ifExists = falseMethods§
public function __construct(
public AlterTarget $target,
public RelationReference $relation,
list<AlterCommand> $commands,
public bool $ifExists = false,
)Parameters
$target | AlterTarget | The kind of relation |
$relation | RelationReference | The relation |
$commands | list<AlterCommand> | The actions in order |
$ifExists | bool | Whether IF EXISTS is written |
Calls 7
- static-call Check::listOf() line 54
- class-const AlterCommand::class() line 54
- static-call Check::input() line 55
- method-call Alterations::admits() line 55
- new Alterations line 55
- class-const AlterTarget::Table() line 56
- class-const AlterTarget::ForeignTable() line 56
public function deriveStatement(Derivation $derivation): voidResolves the relation and derives the actions.
Parameters
$derivation | Derivation |
Calls 2
- method-call Alterations::derive() line 64
- new Alterations line 64
public function deriveRelation(Derivation $derivation, Environment $environment): RelationFactResolves the relation and answers its facts.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 2
- method-call Targets::existing() line 72
- new Targets line 72
public function render(Output $out): voidWrites the statement.
Parameters
$out | Output |
Calls 3
- method-call Output::keyword() line 80
- method-call AlterTarget::keywords() line 80
- method-call Output::node() line 84
Test cases 9§
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 7
AlterKindsTest::testAcceptedAnswersNullForOwnerTocallsAlterKindsTest::testOtherAnswersTheActionOfAColumnChangecallsAlterKindsTest::testRelationWideAnswersTheActionOfARelationOptioncallsIndexConstraintTest::testKindIsUniqueOrPrimaryKeycallsInheritanceChangeTest::testDeriveClauseResolvesTheParentcallsAttachPartitionTest::testDeriveClauseResolvesThePartitioncallsDetachPartitionTest::testDeriveClauseResolvesThePartitioncalls
Relations§
Instantiated in 1
Type declarations 4
- type SqlSemantics\Platform\PostgreSql\Rules\Table\Command\Alterations packages/sql-semantics-postgres/src/Rules/Table/Command/Alterations.php:64
- type SqlSemantics\Platform\PostgreSql\Rules\Table\Command\Alterations packages/sql-semantics-postgres/src/Rules/Table/Command/Alterations.php:93
- type SqlSemantics\Platform\PostgreSql\Rules\Table\Command\GeneratedChanges packages/sql-semantics-postgres/src/Rules/Table/Command/GeneratedChanges.php:47
- type SqlSemantics\Platform\PostgreSql\Rules\Table\Command\GeneratedChanges packages/sql-semantics-postgres/src/Rules/Table/Command/GeneratedChanges.php:98