classColumnDefinition
final class ColumnDefinition
implements Clause
uses Snapshot
@visibility public.The definition of one column: its name, type, storage, compression, foreign-data options and constraints.
Mirrors PostgreSQL's ColumnDef with the constraint list ColQualList builds. The qualifiers are kept in the order written: constraints, deferral attributes (which apply to the constraint before them) and a collation. Their problems are reported by PG-COLUMN-QUALIFIERS-001; their expressions are derived in the environment of the table; the type of an identity column is checked by PG-IDENTITY-TYPE-001. Source: https://www.postgresql.org/docs/17/sql-createtable.html.
$create = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('CREATE TABLE t (a text STORAGE external COMPRESSION lz4 COLLATE "C" NOT NULL)');
$column = $create->statement->definition->elements[0];
[$column->name->value, $column->storage->method->value, $column->compression->method->value, count($column->qualifiers)] // => ['a', 'external', 'lz4', 2]Properties§
public list<GenericOption> $optionspublic list<Clause> $qualifierspublic Name $namepublic TypeName $typepublic ColumnStorage|null $storage = nullpublic ColumnCompression|null $compression = nullMethods§
public function __construct(
public Name $name,
public TypeName $type,
public ColumnStorage|null $storage = null,
public ColumnCompression|null $compression = null,
list<GenericOption> $options = [],
list<Clause> $qualifiers = [],
)Parameters
$name | Name | The column name |
$type | TypeName | The data type |
$storage | ColumnStorage|null | The STORAGE clause |
$compression | ColumnCompression|null | The COMPRESSION clause |
$options | list<GenericOption> | The foreign-data options |
$qualifiers | list<Clause> | The constraints, deferral attributes and collation, in the order written |
Calls 4
- static-call Check::listOf() line 68
- class-const GenericOption::class() line 68
- method-call Qualifiers::checked() line 69
- new Qualifiers line 69
public function deriveClause(Derivation $derivation, Environment $environment): voidDerives the type and the qualifiers in the environment of the table and reports their problems.
Parameters
$derivation | Derivation | |
$environment | Environment |
Called from 1
Calls 8
- method-call TypeName::deriveClause() line 77
- method-call Qualifiers::derive() line 78
- new Qualifiers line 78
- function-call
array_filterline 79 - method-call IdentityColumns::check() line 80
- new IdentityColumns line 80
- method-call ColumnTyping::descriptor() line 80
- new ColumnTyping line 80
public function render(Output $out): voidWrites the column definition.
Parameters
$out | Output |
Calls 3
- method-call Output::name() line 89
- method-call Output::keyword() line 91
- method-call Output::node() line 94
Test cases 14§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 1
ColumnDefinitionTestcalls
Other tests reaching this symbol 13
ColumnTypingTest::testSerialAnswersTheIntegerTypecallsTableConstraintsTest::testTypedElementsRefusesAColumnDefinitioncallsColumnCheckTest::testDeriveClauseResolvesTheConditionAgainstTheTablecallsColumnCheckTest::testKindIsCheckcallsColumnPrimaryKeyTest::testKindIsPrimaryKeycallsColumnUniqueTest::testKindIsUniquecallsDefaultExpressionTest::testKindIsDefaultcallsGeneratedTest::testKindIsGeneratedcallsIdentityTest::testKindIsIdentitycallsNotNullTest::testKindIsNotNullcallsNullAllowedTest::testKindIsNullcallsReferencesTest::testDeriveClauseResolvesTheReferencedTablecallsReferencesTest::testKindIsForeignKeycalls
Relations§
Instantiated in 1
Method calls 1
Type checks 6
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Table\Definition\Declarations::listed() packages/sql-semantics-postgres/src/Rules/Table/Definition/Declarations.php:92
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Table\Definition\Definitions::report() packages/sql-semantics-postgres/src/Rules/Table/Definition/Definitions.php:153
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Table\Definition\Definitions::report() packages/sql-semantics-postgres/src/Rules/Table/Definition/Definitions.php:165
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Table\Definition\GeneratedColumns::inherited() packages/sql-semantics-postgres/src/Rules/Table/Definition/GeneratedColumns.php:181
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Table\RelationKinds::foreign() packages/sql-semantics-postgres/src/Rules/Table/RelationKinds.php:166
- instanceof SqlSemantics\Platform\PostgreSql\Statement\Table\Element\ListedColumns::__construct() packages/sql-semantics-postgres/src/Statement/Table/Element/ListedColumns.php:48