Skip to content

Bug: escaped single quotes in enum/type names not parsed correctly #482

@claude

Description

@claude

Bug: parsing escaped enum names

Enum (and Variant element) names can contain escaped single quotes (\'), but the type string parser does not handle escape sequences in quoted strings.

Affected code

clickhouse/types/type_parser.cpp, TypeParser::NextToken(), the case '\'' branch. There is even an existing TODO comment acknowledging the gap:

// TODO (nemkov): handle escaping ?

When the tokenizer scans for the closing ' it does not skip over \' sequences, so a name like 'val\'ue' would be split at the backslash-escaped quote, returning a truncated/incorrect token.

Example

A query such as:

SELECT variantType(CAST(toDateTime('2024-01-15 10:30:00', 'UTC'), 'Variant(String, DateTime(\'UTC\'))'))

returns a Variant type whose element type string contains single-quoted sub-types. When the client tries to parse the returned column type the tokenizer misreads the quoted segment.

Expected behaviour

The parser should treat \' inside a quoted string as an escaped single quote (part of the name), not as the closing delimiter. The stored value should also have the backslash removed (i.e. \'').

Related

Central tracking issue: ClickHouse/integrations-ai-playground#17

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions