classCreateTable
final class CreateTable
implements SchemaElement, Relation
uses Snapshot
@visibility public.A request to create a table.
Mirrors PostgreSQL's CreateStmt (relation with its persistence, tableElts/inhRelations, ofTypename or partbound, partspec, accessMethod, options, oncommit, tablespacename, if_not_exists). The statement provides one declaration (PG-TABLE-DECLARATION-001) and is the one relation occurrence of the new table: its relation fact resolves to that declaration. The expressions of the definition are derived where that table is the only visible relation (PG-TABLE-DEFINITION-001). The optional WITHOUT OIDS clause is a no-op and is not kept. Source: https://www.postgresql.org/docs/17/sql-createtable.html.
$semantics = new \SqlSemantics\Platform\PostgreSql\Semantics();
$create = $semantics->analyze('CREATE TABLE app.t (id serial PRIMARY KEY, name varchar(20) NOT NULL, note text)', []);
$table = $create->declarations()[0];
[array_map(static fn ($column) => $column->type->name(), $table->columns), $table->columns[2]->nullability, $table->implicit[0]->names[0]->value] // => [['integer', 'character varying(20)', 'text'], \SqlSemantics\Platform\PostgreSql\Model\Statement\Type\Nullability::Nullable, 'tableoid']Properties§
public list<Definition> $optionspublic QualifiedName $namepublic TableForm $definitionpublic Persistence $persistence = Persistence::Permanentpublic bool $ifNotExists = falsepublic PartitionSpec|null $partitioning = nullpublic Name|null $method = nullpublic OnCommit|null $onCommit = nullpublic Name|null $tablespace = nullMethods§
public function __construct(
public QualifiedName $name,
public TableForm $definition,
public Persistence $persistence = Persistence::Permanent,
public bool $ifNotExists = false,
public PartitionSpec|null $partitioning = null,
public Name|null $method = null,
list<Definition> $options = [],
public OnCommit|null $onCommit = null,
public Name|null $tablespace = null,
)Parameters
$name | QualifiedName | The table name |
$definition | TableForm | The columns: a column list, a composite type or a parent partitioned table |
$persistence | Persistence | The persistence |
$ifNotExists | bool | Whether IF NOT EXISTS is written |
$partitioning | PartitionSpec|null | The PARTITION BY clause |
$method | Name|null | The table access method |
$options | list<Definition> | The storage parameters |
$onCommit | OnCommit|null | The ON COMMIT action |
$tablespace | Name|null | The tablespace |
Calls 3
- class-const Persistence::Permanent() line 67
- static-call Check::listOf() line 75
- class-const Definition::class() line 75
public function deriveStatement(Derivation $derivation): voidProvides the declaration and derives the definition against it.
Parameters
$derivation | Derivation |
Calls 2
- method-call Definitions::derive() line 91
- new Definitions line 91
public function deriveElement(Derivation $derivation, Name $schema): voidDerives the statement inside CREATE SCHEMA: an unqualified table belongs to that schema.
Parameters
$derivation | Derivation | |
$schema | Name |
Calls 2
- method-call Definitions::derive() line 99
- new Definitions line 99
public function deriveRelation(Derivation $derivation, Environment $environment): RelationFactAnswers the facts of the new table: its row shape and the declaration, without providing it.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 2
- method-call Definitions::fact() line 107
- new Definitions line 107
public function render(Output $out): voidWrites the statement.
Parameters
$out | Output |
Calls 6
- method-call Output::keyword() line 115
- method-call Spelling::qualified() line 119
- new Spelling line 119
- method-call Output::node() line 120
- method-call Writing::definitions() line 126
- new Writing line 126
Test cases 31§
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 29
LoweringTest::testStatementRoutesAStatementToItsFamilycallsColumnTypingTest::testSerialAnswersTheIntegerTypecallsDefinitionsTest::testDeriveProvidesTheDeclarationcallsDefinitionsTest::testFactDoesNotProvideTheDeclarationcallsDefinitionsTest::testNameIsTemporaryForATemporaryTablecallsTableConstraintsTest::testTypedElementsRefusesAColumnDefinitioncallsColumnCheckTest::testDeriveClauseResolvesTheConditionAgainstTheTablecallsColumnCheckTest::testKindIsCheckcallsColumnPrimaryKeyTest::testKindIsPrimaryKeycallsColumnUniqueTest::testKindIsUniquecallsDefaultExpressionTest::testKindIsDefaultcallsGeneratedTest::testKindIsGeneratedcallsIdentityTest::testKindIsIdentitycallsNotNullTest::testKindIsNotNullcallsNullAllowedTest::testKindIsNullcallsReferencesTest::testDeriveClauseResolvesTheReferencedTablecallsReferencesTest::testKindIsForeignKeycallsConstraintTest::testKindIsTheConstraintTypecallsExclusionTest::testKindIsExclusioncallsForeignKeyTest::testKindIsForeignKeycallsTableCheckTest::testKindIsCheckcallsTablePrimaryKeyTest::testKindIsPrimaryKeycallsTableUniqueTest::testKindIsUniquecallsLikeClauseTest::testDeriveClauseResolvesTheSourceTablecallsListedColumnsTest::testElementsAnswersTheElementsInOrdercallsPartitionOfTest::testElementsAnswersTheColumnOptionscallsTableFormTest::testElementsIsEmptyForATypedTableWithoutElementscallsTypedTableTest::testElementsAnswersTheConstraintscallsRangeLimitTest::testMaximumIsTrueForMaxvaluecalls
Relations§
Instantiated in 1
Constant reads 1
Type checks 3
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Table\Definition\Definitions::derive() packages/sql-semantics-postgres/src/Rules/Table/Definition/Definitions.php:69
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Table\Definition\Definitions::derive() packages/sql-semantics-postgres/src/Rules/Table/Definition/Definitions.php:75
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Table\Definition\Definitions::name() packages/sql-semantics-postgres/src/Rules/Table/Definition/Definitions.php:110
Type declarations 5
- type SqlSemantics\Platform\PostgreSql\Lowering\Table\CreateTableRule packages/sql-semantics-postgres/src/Lowering/Table/CreateTableRule.php:83
- type SqlSemantics\Platform\PostgreSql\Rules\Table\Definition\Definitions packages/sql-semantics-postgres/src/Rules/Table/Definition/Definitions.php:59
- type SqlSemantics\Platform\PostgreSql\Rules\Table\Definition\Definitions packages/sql-semantics-postgres/src/Rules/Table/Definition/Definitions.php:86
- type SqlSemantics\Platform\PostgreSql\Rules\Table\Definition\Definitions packages/sql-semantics-postgres/src/Rules/Table/Definition/Definitions.php:96
- type SqlSemantics\Platform\PostgreSql\Rules\Table\Definition\Definitions packages/sql-semantics-postgres/src/Rules/Table/Definition/Definitions.php:104