```
:) CREATE TEMPORARY TABLE test (x enum('a', 'b'))

CREATE TEMPORARY TABLE test
(
    `x` enum('a', 'b')
)

Query id: 081d03e8-9945-4b0c-a906-4477f4b45d64


0 rows in set. Elapsed: 0.005 sec. 

Received exception from server (version 22.4.1):
Code: 223. DB::Exception: Received from localhost:9000. DB::Exception: Elements of Enum data type must be of form: 'name' = number, where name is string literal and number is an integer. (UNEXPECTED_AST_STRUCTURE)
```
{
    if (!arguments || arguments->children.empty())
        throw Exception("Enum data type cannot be empty", ErrorCodes::EMPTY_DATA_PASSED);
    autoAssignNumberForEnum(arguments);
    
    for (const ASTPtr & child : arguments->children)
    {
        checkASTStructure(child);
        const auto * func = child->as<ASTFunction>();
        const auto * value_literal = func->arguments->children[1]->as<ASTLiteral>();
        if (!value_literal
            || (value_literal->value.getType() != Field::Types::UInt64 && value_literal->value.getType() != Field::Types::Int64))
            throw Exception("Elements of Enum data type must be of form: 'name' = number, where name is string literal and number is an integer",
                    ErrorCodes::UNEXPECTED_AST_STRUCTURE);
        Int64 value = value_literal->value.get<Int64>();
        if (value > std::numeric_limits<Int8>::max() || value < std::numeric_limits<Int8>::min())
            return createExact<DataTypeEnum16>(arguments);
    }
    return createExact<DataTypeEnum8>(arguments);
}
void registerDataTypeEnum(DataTypeFactory & factory)
{
    factory.registerDataType("Enum8", createExact<DataTypeEnum<Int8>>);
    factory.registerDataType("Enum16", createExact<DataTypeEnum<Int16>>);
    factory.registerDataType("Enum", create);
    
    factory.registerAlias("ENUM", "Enum", DataTypeFactory::CaseInsensitive);
}
}