Helpers for safely quoting and sanitizing ClickHouse identifiers.
ClickHouse identifiers (table names, column names, database names) may be quoted with backticks. Unquoted identifiers are limited to a restricted set of characters. This module provides validation and quoting helpers so the data layer can build SQL safely without opening SQL-injection vectors.
Summary
Functions
Quotes an identifier with backticks, escaping any embedded backticks.
Sanitizes an identifier, raising ArgumentError if it is invalid.
Returns true if the given identifier is a valid unquoted ClickHouse identifier.
Validates a database name, raising ArgumentError if invalid.
Validates a table name, raising ArgumentError if invalid.
Functions
Quotes an identifier with backticks, escaping any embedded backticks.
Examples
iex> AshClickhouse.Identifier.quote_name("users")
"`users`"
iex> AshClickhouse.Identifier.quote_name("my`table")
"`my``table`"Column identifiers go through quote_name/1 (backtick-escaping) rather than
the stricter sanitize!/1 used for table/database names. This is intentional:
Ash attribute names are derived from atoms and are already safe, and
quote_name/1 additionally tolerates arbitrary (e.g. expression-derived)
column labels without rejecting valid identifiers that merely fall outside the
[a-zA-Z_][a-zA-Z0-9_]* pattern. Table and database names, by contrast, are
developer-supplied strings validated up front by sanitize!/1 so a bad name
fails loudly at DDL time rather than producing malformed SQL.
Sanitizes an identifier, raising ArgumentError if it is invalid.
A valid ClickHouse identifier consists of letters, digits, and underscores, and must not start with a digit.
Returns true if the given identifier is a valid unquoted ClickHouse identifier.
@spec validate_database!(String.t() | nil) :: :ok
Validates a database name, raising ArgumentError if invalid.
@spec validate_table!(String.t()) :: :ok
Validates a table name, raising ArgumentError if invalid.