classDefinitions
final class Definitions
Derives CREATE TABLE and CREATE FOREIGN TABLE.
Rule: PG-TABLE-DEFINITION-001. The new table is named as written; a temporary table with an unqualified name belongs to the temporary schema pg_temp, and inside CREATE SCHEMA an unqualified table belongs to the schema being created. The statement provides the declaration of PG-TABLE-DECLARATION-001 and records it as its own relation fact. The parents of INHERITS and PARTITION OF are resolved (PG-TABLE-TARGET-001); a parent of INHERITS must be a table or a foreign table (PG-RELATION-KIND-001). Every expression of the definition (constraints, generated columns, partition keys) is derived where the new table is the only visible relation, its system columns included; defaults and partition bound values see no column. Problems: a column name written twice, a column named like a system column, more than one primary key, an array of a serial type, a primary key, unique, exclusion or foreign key constraint of a foreign table, and the generation rules of PG-GENERATED-COLUMN-001. Source: https://www.postgresql.org/docs/17/sql-createtable.html. Termination: one pass over the elements. Status: Implemented.
Methods§
public function derive(
CreateTable|CreateForeignTable $create,
Derivation $derivation,
?Name $schema,
): voidProvides the declaration and derives the definition; $schema is the schema of an enclosing CREATE SCHEMA.
Parameters
$create | CreateTable|CreateForeignTable | |
$derivation | Derivation | |
$schema | ?Name |
Called from 3
- method-call SqlSemantics\Platform\PostgreSql\Statement\Table\CreateForeignTable::deriveStatement() packages/sql-semantics-postgres/src/Statement/Table/CreateForeignTable.php:66
- method-call SqlSemantics\Platform\PostgreSql\Statement\Table\CreateTable::deriveStatement() packages/sql-semantics-postgres/src/Statement/Table/CreateTable.php:91
- method-call SqlSemantics\Platform\PostgreSql\Statement\Table\CreateTable::deriveElement() packages/sql-semantics-postgres/src/Statement/Table/CreateTable.php:99
Calls 20
- method-call Definitions::name() line 61
- method-call Declarations::table() line 62
- new Declarations line 62
- method-call Definitions::kind() line 62
- method-call Derivation::declare() line 63
- new Targets line 64
- method-call Derivation::target() line 65
- new RelationFact line 65
- method-call Targets::shape() line 65
- new DeclaredTable line 65
- method-call Targets::scope() line 66
- method-call Targets::implicit() line 66
- method-call Definitions::report() line 67
- method-call GeneratedColumns::inherited() line 68
- new GeneratedColumns line 68
- method-call CreationSchemas::check() line 70
- new CreationSchemas line 70
- method-call RelationKinds::foreign() line 72
- new RelationKinds line 72
- method-call Definitions::elements() line 74
public function fact(
CreateTable|CreateForeignTable $create,
Derivation $derivation,
?Name $schema,
): RelationFactAnswers the facts of the new table without providing its declaration.
Parameters
$create | CreateTable|CreateForeignTable | |
$derivation | Derivation | |
$schema | ?Name |
Returns
Test cases 1
Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Statement\Table\CreateForeignTable::deriveRelation() packages/sql-semantics-postgres/src/Statement/Table/CreateForeignTable.php:74
- method-call SqlSemantics\Platform\PostgreSql\Statement\Table\CreateTable::deriveRelation() packages/sql-semantics-postgres/src/Statement/Table/CreateTable.php:107
Calls 8
- method-call Declarations::table() line 88
- new Declarations line 88
- method-call Definitions::name() line 88
- method-call Definitions::kind() line 88
- new RelationFact line 90
- method-call Targets::shape() line 90
- new Targets line 90
- new DeclaredTable line 90
public function kind(CreateTable|CreateForeignTable $create): RelationKindAnswers the kind of relation the definition declares.
Parameters
$create | CreateTable|CreateForeignTable |
Returns
Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Rules\Table\Definition\Definitions::derive() packages/sql-semantics-postgres/src/Rules/Table/Definition/Definitions.php:62
- method-call SqlSemantics\Platform\PostgreSql\Rules\Table\Definition\Definitions::fact() packages/sql-semantics-postgres/src/Rules/Table/Definition/Definitions.php:88
Calls 2
- class-const RelationKind::ForeignTable() line 98
- class-const RelationKind::BaseTable() line 98
public function name(CreateTable|CreateForeignTable $create, ?Name $schema): QualifiedNameAnswers the name the new table is declared under.
Parameters
$create | CreateTable|CreateForeignTable | |
$schema | ?Name |
Returns
Test cases 1
Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Rules\Table\Definition\Definitions::derive() packages/sql-semantics-postgres/src/Rules/Table/Definition/Definitions.php:61
- method-call SqlSemantics\Platform\PostgreSql\Rules\Table\Definition\Definitions::fact() packages/sql-semantics-postgres/src/Rules/Table/Definition/Definitions.php:88
Calls 2
- new QualifiedName line 111
- new Name line 111
public function elements(TableForm $form, Derivation $derivation, Environment $scope): voidResolves the parents and derives the elements and the partition bound.
Parameters
$form | TableForm | |
$derivation | Derivation | |
$scope | Environment |
Called from 1
Calls 10
- new Targets line 122
- new RelationKinds line 123
- method-call RelationKinds::of() line 125
- method-call Derivation::target() line 125
- method-call Targets::resolve() line 125
- method-call RelationKinds::require() line 126
- class-const RelationKind::BaseTable() line 126
- class-const RelationKind::ForeignTable() line 126
- class-const KindRule::InheritedRelation() line 126
- method-call TableForm::elements() line 132
public function report(TableForm $form, Derivation $derivation, QualifiedName $name): voidReports repeated column names (the columns a LIKE clause copies included), system column names, several primary keys and serial arrays.
Parameters
$form | TableForm | |
$derivation | Derivation | |
$name | QualifiedName |
Called from 1
Calls 13
- new SystemColumns line 144
- method-call TableForm::elements() line 145
- method-call Derivation::table() line 146
- method-call Derivation::environment() line 146
- method-call Derivation::report() line 149
- new DefinitionProblem line 149
- class-const DefinitionRule::DuplicateColumn() line 149
- method-call SystemColumns::reserved() line 158
- class-const DefinitionRule::SystemColumnName() line 159
- method-call ColumnTyping::serial() line 165
- new ColumnTyping line 165
- class-const DefinitionRule::SerialArray() line 166
- class-const DefinitionRule::MultiplePrimaryKeys() line 171
Test cases 2§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 2
Relations§
Instantiated in 5
- new SqlSemantics\Platform\PostgreSql\Statement\Table\CreateForeignTable::deriveStatement() packages/sql-semantics-postgres/src/Statement/Table/CreateForeignTable.php:66
- new SqlSemantics\Platform\PostgreSql\Statement\Table\CreateForeignTable::deriveRelation() packages/sql-semantics-postgres/src/Statement/Table/CreateForeignTable.php:74
- new SqlSemantics\Platform\PostgreSql\Statement\Table\CreateTable::deriveStatement() packages/sql-semantics-postgres/src/Statement/Table/CreateTable.php:91
- new SqlSemantics\Platform\PostgreSql\Statement\Table\CreateTable::deriveElement() packages/sql-semantics-postgres/src/Statement/Table/CreateTable.php:99
- new SqlSemantics\Platform\PostgreSql\Statement\Table\CreateTable::deriveRelation() packages/sql-semantics-postgres/src/Statement/Table/CreateTable.php:107
Method calls 5
- method-call SqlSemantics\Platform\PostgreSql\Statement\Table\CreateForeignTable::deriveStatement() packages/sql-semantics-postgres/src/Statement/Table/CreateForeignTable.php:66
- method-call SqlSemantics\Platform\PostgreSql\Statement\Table\CreateForeignTable::deriveRelation() packages/sql-semantics-postgres/src/Statement/Table/CreateForeignTable.php:74
- method-call SqlSemantics\Platform\PostgreSql\Statement\Table\CreateTable::deriveStatement() packages/sql-semantics-postgres/src/Statement/Table/CreateTable.php:91
- method-call SqlSemantics\Platform\PostgreSql\Statement\Table\CreateTable::deriveElement() packages/sql-semantics-postgres/src/Statement/Table/CreateTable.php:99
- method-call SqlSemantics\Platform\PostgreSql\Statement\Table\CreateTable::deriveRelation() packages/sql-semantics-postgres/src/Statement/Table/CreateTable.php:107