final class ColumnRule
Restricted visibility: declared "@visibility SqlSemantics\Platform\MySql". Code outside that scope must not name this declaration.

Lowers column specifications: the data type, the attributes and the generation expression of a column.

Rule: MYSQL-COLUMN-SPECIFICATION-001. Scope: field_def, opt_attribute, opt_attribute_list, opt_column_attribute_list, column_attribute_list, opt_gcol_attribute_list, gcol_attribute_list, opt_generated_always, opt_stored_attribute, generated_column_func, parse_gcol_expr. MySQL 5.6 writes the type and the attributes directly in field_spec. A CHECK clause after a 5.x column definition is the last attribute; an inline REFERENCES clause is the reference of the specification. GENERATED ALWAYS is optional and not kept. The parser of MySQL 8.0 and later reads every column attribute after a generation expression and then refuses DEFAULT, ON UPDATE, AUTO_INCREMENT, SERIAL DEFAULT VALUE, COLUMN_FORMAT and STORAGE there, and the type SERIAL, with ER_WRONG_USAGE ("Incorrect

  • usage of DEFAULT and generated column"; sql/parse_tree_column_attrs.h

PT_default_column_attr::do_contextualize and its siblings, PT_generated_field_def_base); 5.7 has no grammar for them. Constructs: OrdinaryColumn, GeneratedColumn, ParseGeneratedColumn. Terminates: lists are flattened iteratively. Source: https://dev.mysql.com/doc/refman/8.4/en/create-table.html, https://dev.mysql.com/doc/refman/8.4/en/create-table-generated-columns.html. Status: Implemented.

Methods§

public function __construct(private Lowering $lowering)

Parameters

$loweringLoweringThe lowering this rule belongs to
public function specification(
    Node $definition,
    ?Node $attributes = null,
    ?References $references = null,
    list<ColumnAttribute> $trailing = [],
): ColumnSpecification

Lowers a column specification: a node of field_def, or the nodes of type and opt_attribute (5.6).

Parameters

$definitionNode
$attributes?Node
$references?References
$trailinglist<ColumnAttribute>Attributes written after the specification, such as a 5.x column CHECK

Throws

ImplementationGap When a production has no rule
AnalysisException When a generated column has an attribute or type the server refuses for it
Test cases 3
Called from 5
Calls 10
public function refuse(list<ColumnAttribute> $attributes, TypeName $type): void

Refuses, as the server's parser does, the attributes and the type a generated column cannot have.

The first such attribute in written order is named, then the type SERIAL.

Parameters

$attributeslist<ColumnAttribute>The attributes in written order
$typeTypeName

Throws

AnalysisException When the generated column has DEFAULT, ON UPDATE, AUTO_INCREMENT, SERIAL DEFAULT VALUE, COLUMN_FORMAT or STORAGE, or the type SERIAL
Called from 1
Calls 4
public function always(Node $words): void

Confirms the optional words GENERATED ALWAYS: a node of opt_generated_always.

Parameters

$wordsNode

Throws

ImplementationGap When the production has no rule
Test cases 1
Called from 1
Calls 1
public function storage(Node $storage): ?GeneratedStorage
public function parse(Node $statement): ParseGeneratedColumn

Private surface 4§

Implementation details, listed for orientation only.

private const LISTS = ['opt_attribute_list: opt_attribute_list attribute', 'opt_attribute_list: attri…
private const OPTIONAL = ['opt_attribute:' => false, 'opt_attribute: opt_attribute_list' => true, 'opt_c…
private const GENERATED = ['field_def: type opt_collate_explicit opt_generated_always AS ( generated_colu…
private Lowering $lowering

Test cases 8§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 8

Relations§

Instantiated in 4
Method calls 6