sqlglot.dialects.bigquery
1from __future__ import annotations 2 3import typing as t 4 5 6from sqlglot.optimizer.annotate_types import TypeAnnotator 7 8from sqlglot import exp, jsonpath, tokens 9from sqlglot.parsers.bigquery import BigQueryParser 10from sqlglot.generators.bigquery import BigQueryGenerator 11from sqlglot.dialects.dialect import ( 12 Dialect, 13 NormalizationStrategy, 14) 15from sqlglot.tokens import TokenType 16from sqlglot.typing.bigquery import EXPRESSION_METADATA 17 18if t.TYPE_CHECKING: 19 from sqlglot.optimizer.annotate_types import TypeAnnotator 20 21 22class BigQuery(Dialect): 23 WEEK_OFFSET = -1 24 UNNEST_COLUMN_ONLY = True 25 SUPPORTS_USER_DEFINED_TYPES = False 26 LOG_BASE_FIRST = False 27 HEX_LOWERCASE = True 28 FORCE_EARLY_ALIAS_REF_EXPANSION = True 29 EXPAND_ONLY_GROUP_ALIAS_REF = True 30 ORIGINAL_NAME_META_KEY = "bigquery_name" 31 HEX_STRING_IS_INTEGER_TYPE = True 32 BYTE_STRING_IS_BYTES_TYPE = True 33 UUID_IS_STRING_TYPE = True 34 ANNOTATE_ALL_SCOPES = True 35 PROJECTION_ALIASES_SHADOW_SOURCE_NAMES = True 36 TABLES_REFERENCEABLE_AS_COLUMNS = True 37 TABLE_ALIASES_SHADOW_COLUMN_NAMES = True 38 SUPPORTS_STRUCT_STAR_EXPANSION = True 39 EXCLUDES_PSEUDOCOLUMNS_FROM_STAR = True 40 QUERY_RESULTS_ARE_STRUCTS = True 41 JSON_EXTRACT_SCALAR_SCALAR_ONLY = True 42 JSON_PATH_SINGLE_DOT_IS_WILDCARD = True 43 LEAST_GREATEST_IGNORES_NULLS = False 44 DEFAULT_NULL_TYPE = exp.DType.BIGINT 45 PRIORITIZE_NON_LITERAL_TYPES = True 46 ALIAS_POST_VERSION = False 47 48 # https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/string_functions#initcap 49 INITCAP_DEFAULT_DELIMITER_CHARS = ' \t\n\r\f\v\\[\\](){}/|<>!?@"^#$&~_,.:;*%+\\-' 50 51 # https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#case_sensitivity 52 NORMALIZATION_STRATEGY = NormalizationStrategy.CASE_INSENSITIVE_EXCEPT_TABLES 53 ASCII_ONLY_NORMALIZATION = True 54 55 # bigquery udfs are case sensitive 56 NORMALIZE_FUNCTIONS = False 57 58 # https://cloud.google.com/bigquery/docs/reference/standard-sql/format-elements#format_elements_date_time 59 TIME_MAPPING = { 60 "%x": "%m/%d/%y", 61 "%D": "%m/%d/%y", 62 "%E6S": "%S.%f", 63 "%e": "%-d", 64 "%F": "%Y-%m-%d", 65 "%T": "%H:%M:%S", 66 "%c": "%a %b %e %H:%M:%S %Y", 67 } 68 69 INVERSE_TIME_MAPPING = { 70 # Preserve %E6S instead of expanding to %T.%f - since both %E6S & %T.%f are semantically different in BigQuery 71 # %E6S is semantically different from %T.%f: %E6S works as a single atomic specifier for seconds with microseconds, while %T.%f expands incorrectly and fails to parse. 72 "%H:%M:%S.%f": "%H:%M:%E6S", 73 # Milliseconds are only written, so BigQuery's own %E3S is read and kept as is 74 "%S.%f_three": "%E3S", 75 "%H:%M:%S.%f_three": "%H:%M:%E3S", 76 } 77 78 FORMAT_MAPPING = { 79 "dd": "%d", 80 "DD": "%d", 81 "mm": "%m", 82 "MM": "%m", 83 "mon": "%b", 84 "MON": "%b", 85 "month": "%B", 86 "MONTH": "%B", 87 "yyyy": "%Y", 88 "YYYY": "%Y", 89 "yy": "%y", 90 "YY": "%y", 91 "HH": "%I", 92 "HH12": "%I", 93 "hh24": "%H", 94 "HH24": "%H", 95 "mi": "%M", 96 "MI": "%M", 97 "ss": "%S", 98 "SS": "%S", 99 "SSSSS": "%f", 100 "tzh": "%z", 101 "TZH": "%z", 102 } 103 104 # The _PARTITIONTIME and _PARTITIONDATE pseudo-columns are not returned by a SELECT * statement 105 # https://cloud.google.com/bigquery/docs/querying-partitioned-tables#query_an_ingestion-time_partitioned_table 106 # https://cloud.google.com/bigquery/docs/querying-wildcard-tables#scanning_a_range_of_tables_using_table_suffix 107 # https://cloud.google.com/bigquery/docs/query-cloud-storage-data#query_the_file_name_pseudo-column 108 PSEUDOCOLUMNS = { 109 "_PARTITIONTIME", 110 "_PARTITIONDATE", 111 "_TABLE_SUFFIX", 112 "_FILE_NAME", 113 "_DBT_MAX_PARTITION", 114 } 115 116 # All set operations require either a DISTINCT or ALL specifier 117 SET_OP_DISTINCT_BY_DEFAULT = dict.fromkeys((exp.Except, exp.Intersect, exp.Union), None) 118 119 # https://cloud.google.com/bigquery/docs/reference/standard-sql/navigation_functions#percentile_cont 120 COERCES_TO = { 121 **TypeAnnotator.COERCES_TO, 122 exp.DType.BIGDECIMAL: {exp.DType.DOUBLE}, 123 } 124 COERCES_TO[exp.DType.DECIMAL] |= {exp.DType.BIGDECIMAL} 125 COERCES_TO[exp.DType.BIGINT] |= {exp.DType.BIGDECIMAL} 126 COERCES_TO[exp.DType.VARCHAR] |= { 127 exp.DType.DATE, 128 exp.DType.DATETIME, 129 exp.DType.TIME, 130 exp.DType.TIMESTAMP, 131 exp.DType.TIMESTAMPTZ, 132 } 133 134 EXPRESSION_METADATA = EXPRESSION_METADATA.copy() 135 136 class JSONPathTokenizer(jsonpath.JSONPathTokenizer): 137 VAR_TOKENS = { 138 *jsonpath.JSONPathTokenizer.VAR_TOKENS, 139 TokenType.DASH, 140 TokenType.NUMBER, 141 } 142 143 class Tokenizer(tokens.Tokenizer): 144 NUMERIC_ESCAPES = { 145 "x": (16, 2, 2, 0xFF), 146 "X": (16, 2, 2, 0xFF), 147 "u": (16, 4, 4, 0xFFFF), 148 "U": (16, 8, 8, 0x10FFFF), 149 "0": (8, 3, 3, 0xFF), 150 } 151 DROP_UNKNOWN_ESCAPES = True 152 QUOTES = ["'", '"', '"""', "'''"] 153 COMMENTS = ["--", "#", ("/*", "*/")] 154 IDENTIFIERS = ["`"] 155 IDENTIFIER_ESCAPES = ["\\"] 156 STRING_ESCAPES = ["\\"] 157 158 HEX_STRINGS = [("0x", ""), ("0X", "")] 159 160 BYTE_STRINGS = [(prefix + q, q) for q in t.cast(list[str], QUOTES) for prefix in ("b", "B")] 161 162 RAW_STRINGS = [(prefix + q, q) for q in t.cast(list[str], QUOTES) for prefix in ("r", "R")] 163 164 NESTED_COMMENTS = False 165 166 KEYWORDS = { 167 **tokens.Tokenizer.KEYWORDS, 168 "ANY TYPE": TokenType.VARIANT, 169 "BEGIN": TokenType.COMMAND, 170 "BEGIN TRANSACTION": TokenType.BEGIN, 171 "BYTEINT": TokenType.INT, 172 "BYTES": TokenType.BINARY, 173 "CURRENT_DATETIME": TokenType.CURRENT_DATETIME, 174 "DATETIME": TokenType.TIMESTAMP, 175 "DECLARE": TokenType.DECLARE, 176 "ELSEIF": TokenType.COMMAND, 177 "EXCEPTION": TokenType.COMMAND, 178 "EXPORT": TokenType.EXPORT, 179 "FLOAT64": TokenType.DOUBLE, 180 "LOOP": TokenType.COMMAND, 181 "MODEL": TokenType.MODEL, 182 "RECORD": TokenType.STRUCT, 183 "REPEAT": TokenType.COMMAND, 184 "TIMESTAMP": TokenType.TIMESTAMPTZ, 185 "WHILE": TokenType.COMMAND, 186 } 187 KEYWORDS.pop("ISNULL") 188 KEYWORDS.pop("DIV") 189 KEYWORDS.pop("VALUES") 190 KEYWORDS.pop("/*+") 191 192 Parser = BigQueryParser 193 194 Generator = BigQueryGenerator
23class BigQuery(Dialect): 24 WEEK_OFFSET = -1 25 UNNEST_COLUMN_ONLY = True 26 SUPPORTS_USER_DEFINED_TYPES = False 27 LOG_BASE_FIRST = False 28 HEX_LOWERCASE = True 29 FORCE_EARLY_ALIAS_REF_EXPANSION = True 30 EXPAND_ONLY_GROUP_ALIAS_REF = True 31 ORIGINAL_NAME_META_KEY = "bigquery_name" 32 HEX_STRING_IS_INTEGER_TYPE = True 33 BYTE_STRING_IS_BYTES_TYPE = True 34 UUID_IS_STRING_TYPE = True 35 ANNOTATE_ALL_SCOPES = True 36 PROJECTION_ALIASES_SHADOW_SOURCE_NAMES = True 37 TABLES_REFERENCEABLE_AS_COLUMNS = True 38 TABLE_ALIASES_SHADOW_COLUMN_NAMES = True 39 SUPPORTS_STRUCT_STAR_EXPANSION = True 40 EXCLUDES_PSEUDOCOLUMNS_FROM_STAR = True 41 QUERY_RESULTS_ARE_STRUCTS = True 42 JSON_EXTRACT_SCALAR_SCALAR_ONLY = True 43 JSON_PATH_SINGLE_DOT_IS_WILDCARD = True 44 LEAST_GREATEST_IGNORES_NULLS = False 45 DEFAULT_NULL_TYPE = exp.DType.BIGINT 46 PRIORITIZE_NON_LITERAL_TYPES = True 47 ALIAS_POST_VERSION = False 48 49 # https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/string_functions#initcap 50 INITCAP_DEFAULT_DELIMITER_CHARS = ' \t\n\r\f\v\\[\\](){}/|<>!?@"^#$&~_,.:;*%+\\-' 51 52 # https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#case_sensitivity 53 NORMALIZATION_STRATEGY = NormalizationStrategy.CASE_INSENSITIVE_EXCEPT_TABLES 54 ASCII_ONLY_NORMALIZATION = True 55 56 # bigquery udfs are case sensitive 57 NORMALIZE_FUNCTIONS = False 58 59 # https://cloud.google.com/bigquery/docs/reference/standard-sql/format-elements#format_elements_date_time 60 TIME_MAPPING = { 61 "%x": "%m/%d/%y", 62 "%D": "%m/%d/%y", 63 "%E6S": "%S.%f", 64 "%e": "%-d", 65 "%F": "%Y-%m-%d", 66 "%T": "%H:%M:%S", 67 "%c": "%a %b %e %H:%M:%S %Y", 68 } 69 70 INVERSE_TIME_MAPPING = { 71 # Preserve %E6S instead of expanding to %T.%f - since both %E6S & %T.%f are semantically different in BigQuery 72 # %E6S is semantically different from %T.%f: %E6S works as a single atomic specifier for seconds with microseconds, while %T.%f expands incorrectly and fails to parse. 73 "%H:%M:%S.%f": "%H:%M:%E6S", 74 # Milliseconds are only written, so BigQuery's own %E3S is read and kept as is 75 "%S.%f_three": "%E3S", 76 "%H:%M:%S.%f_three": "%H:%M:%E3S", 77 } 78 79 FORMAT_MAPPING = { 80 "dd": "%d", 81 "DD": "%d", 82 "mm": "%m", 83 "MM": "%m", 84 "mon": "%b", 85 "MON": "%b", 86 "month": "%B", 87 "MONTH": "%B", 88 "yyyy": "%Y", 89 "YYYY": "%Y", 90 "yy": "%y", 91 "YY": "%y", 92 "HH": "%I", 93 "HH12": "%I", 94 "hh24": "%H", 95 "HH24": "%H", 96 "mi": "%M", 97 "MI": "%M", 98 "ss": "%S", 99 "SS": "%S", 100 "SSSSS": "%f", 101 "tzh": "%z", 102 "TZH": "%z", 103 } 104 105 # The _PARTITIONTIME and _PARTITIONDATE pseudo-columns are not returned by a SELECT * statement 106 # https://cloud.google.com/bigquery/docs/querying-partitioned-tables#query_an_ingestion-time_partitioned_table 107 # https://cloud.google.com/bigquery/docs/querying-wildcard-tables#scanning_a_range_of_tables_using_table_suffix 108 # https://cloud.google.com/bigquery/docs/query-cloud-storage-data#query_the_file_name_pseudo-column 109 PSEUDOCOLUMNS = { 110 "_PARTITIONTIME", 111 "_PARTITIONDATE", 112 "_TABLE_SUFFIX", 113 "_FILE_NAME", 114 "_DBT_MAX_PARTITION", 115 } 116 117 # All set operations require either a DISTINCT or ALL specifier 118 SET_OP_DISTINCT_BY_DEFAULT = dict.fromkeys((exp.Except, exp.Intersect, exp.Union), None) 119 120 # https://cloud.google.com/bigquery/docs/reference/standard-sql/navigation_functions#percentile_cont 121 COERCES_TO = { 122 **TypeAnnotator.COERCES_TO, 123 exp.DType.BIGDECIMAL: {exp.DType.DOUBLE}, 124 } 125 COERCES_TO[exp.DType.DECIMAL] |= {exp.DType.BIGDECIMAL} 126 COERCES_TO[exp.DType.BIGINT] |= {exp.DType.BIGDECIMAL} 127 COERCES_TO[exp.DType.VARCHAR] |= { 128 exp.DType.DATE, 129 exp.DType.DATETIME, 130 exp.DType.TIME, 131 exp.DType.TIMESTAMP, 132 exp.DType.TIMESTAMPTZ, 133 } 134 135 EXPRESSION_METADATA = EXPRESSION_METADATA.copy() 136 137 class JSONPathTokenizer(jsonpath.JSONPathTokenizer): 138 VAR_TOKENS = { 139 *jsonpath.JSONPathTokenizer.VAR_TOKENS, 140 TokenType.DASH, 141 TokenType.NUMBER, 142 } 143 144 class Tokenizer(tokens.Tokenizer): 145 NUMERIC_ESCAPES = { 146 "x": (16, 2, 2, 0xFF), 147 "X": (16, 2, 2, 0xFF), 148 "u": (16, 4, 4, 0xFFFF), 149 "U": (16, 8, 8, 0x10FFFF), 150 "0": (8, 3, 3, 0xFF), 151 } 152 DROP_UNKNOWN_ESCAPES = True 153 QUOTES = ["'", '"', '"""', "'''"] 154 COMMENTS = ["--", "#", ("/*", "*/")] 155 IDENTIFIERS = ["`"] 156 IDENTIFIER_ESCAPES = ["\\"] 157 STRING_ESCAPES = ["\\"] 158 159 HEX_STRINGS = [("0x", ""), ("0X", "")] 160 161 BYTE_STRINGS = [(prefix + q, q) for q in t.cast(list[str], QUOTES) for prefix in ("b", "B")] 162 163 RAW_STRINGS = [(prefix + q, q) for q in t.cast(list[str], QUOTES) for prefix in ("r", "R")] 164 165 NESTED_COMMENTS = False 166 167 KEYWORDS = { 168 **tokens.Tokenizer.KEYWORDS, 169 "ANY TYPE": TokenType.VARIANT, 170 "BEGIN": TokenType.COMMAND, 171 "BEGIN TRANSACTION": TokenType.BEGIN, 172 "BYTEINT": TokenType.INT, 173 "BYTES": TokenType.BINARY, 174 "CURRENT_DATETIME": TokenType.CURRENT_DATETIME, 175 "DATETIME": TokenType.TIMESTAMP, 176 "DECLARE": TokenType.DECLARE, 177 "ELSEIF": TokenType.COMMAND, 178 "EXCEPTION": TokenType.COMMAND, 179 "EXPORT": TokenType.EXPORT, 180 "FLOAT64": TokenType.DOUBLE, 181 "LOOP": TokenType.COMMAND, 182 "MODEL": TokenType.MODEL, 183 "RECORD": TokenType.STRUCT, 184 "REPEAT": TokenType.COMMAND, 185 "TIMESTAMP": TokenType.TIMESTAMPTZ, 186 "WHILE": TokenType.COMMAND, 187 } 188 KEYWORDS.pop("ISNULL") 189 KEYWORDS.pop("DIV") 190 KEYWORDS.pop("VALUES") 191 KEYWORDS.pop("/*+") 192 193 Parser = BigQueryParser 194 195 Generator = BigQueryGenerator
First day of the week in DATE_TRUNC(week). Defaults to 0 (Monday). -1 would be Sunday.
Whether the base comes first in the LOG function.
Possible values: True, False, None (two arguments are not supported by LOG)
Whether alias reference expansion (_expand_alias_refs()) should run before column qualification (_qualify_columns()).
For example:
WITH data AS ( SELECT 1 AS id, 2 AS my_id ) SELECT id AS my_id FROM data WHERE my_id = 1 GROUP BY my_id, HAVING my_id = 1
In most dialects, "my_id" would refer to "data.my_id" across the query, except: - BigQuery, which will forward the alias to GROUP BY + HAVING clauses i.e it resolves to "WHERE my_id = 1 GROUP BY id HAVING id = 1" - Clickhouse, which will forward the alias across the query i.e it resolves to "WHERE id = 1 GROUP BY id HAVING id = 1"
Whether alias reference expansion before qualification should only happen for the GROUP BY clause.
Dialect-specific metadata key for preserving original function names, or None to disable. Only generators using the same key reuse these names, allowing round trips of aliases that share an AST node, e.g. JSON_VALUE vs JSON_EXTRACT_SCALAR in BigQuery.
Whether hex strings such as x'CC' evaluate to integer or binary/blob type
Whether byte string literals (ex: BigQuery's b'...') are typed as BYTES/BINARY
Whether to annotate all scopes during optimization. Used by BigQuery for UNNEST support.
Whether projection alias names can shadow table/source names in GROUP BY and HAVING clauses.
In BigQuery, when a projection alias has the same name as a source table, the alias takes precedence in GROUP BY and HAVING clauses, and the table becomes inaccessible by that name.
For example, in BigQuery: SELECT id, ARRAY_AGG(col) AS custom_fields FROM custom_fields GROUP BY id HAVING id >= 1
The "custom_fields" source is shadowed by the projection alias, so we cannot qualify "id" with "custom_fields" in GROUP BY/HAVING.
Whether table names can be referenced as columns (treated as structs).
BigQuery allows tables to be referenced as columns in queries, automatically treating them as struct values containing all the table's columns.
For example, in BigQuery: SELECT t FROM my_table AS t -- Returns entire row as a struct
Whether a whole-row reference to a table alias takes precedence over a same-named column.
Whether the dialect supports expanding struct fields using star notation (e.g., struct_col.*).
BigQuery allows struct fields to be expanded with the star operator:
SELECT t.struct_col.* FROM table t
RisingWave also allows struct field expansion with the star operator using parentheses:
SELECT (t.struct_col).* FROM table t
This expands to all fields within the struct.
Whether pseudocolumns should be excluded from star expansion (SELECT *).
Pseudocolumns are special dialect-specific columns (e.g., Oracle's ROWNUM, ROWID, LEVEL, or BigQuery's _PARTITIONTIME, _PARTITIONDATE) that are implicitly available but not part of the table schema. When this is True, SELECT * will not include these pseudocolumns; they must be explicitly selected.
Whether query results are typed as structs in metadata for type inference.
In BigQuery, subqueries store their column types as a STRUCT in metadata,
enabling special type inference for ARRAY(SELECT ...) expressions:
ARRAY(SELECT x, y FROM t) → ARRAY For single column subqueries, BigQuery unwraps the struct:
ARRAY(SELECT x FROM t) → ARRAY This is metadata-only for type inference.
Whether JSON_EXTRACT_SCALAR returns null if a non-scalar value is selected.
Whether a single DOT in a JSON path (e.g. $.) is treated as a valid wildcard key.
Whether LEAST/GREATEST functions ignore NULL values, e.g:
- BigQuery, Snowflake, MySQL, Presto/Trino: LEAST(1, NULL, 2) -> NULL
- Spark, Postgres, DuckDB, TSQL: LEAST(1, NULL, 2) -> 1
The default type of NULL for producing the correct projection type.
For example, in BigQuery the default type of the NULL value is INT64.
Whether to prioritize non-literal types over literals during type annotation.
Whether the table alias comes after version (timestamp or iceberg snapshot).
Specifies the strategy according to which identifiers should be normalized.
Whether identifiers are only normalized with respect to ASCII characters, e.g. Ä and
ä are different identifiers in DuckDB, but the same identifier in Spark.
Determines how function names are going to be normalized.
Possible values:
"upper" or True: Convert names to uppercase. "lower": Convert names to lowercase. False: Disables function name normalization.
Associates this dialect's time formats with their equivalent Python strftime formats.
Helper which is used for parsing the special syntax CAST(x AS DATE FORMAT 'yyyy').
If empty, the corresponding trie will be constructed off of TIME_MAPPING.
Columns that are auto-generated by the engine corresponding to this dialect.
For example, such columns may be excluded from SELECT * queries.
Whether a set operation uses DISTINCT by default. This is None when either DISTINCT or ALL
must be explicitly specified.
Mapping of an escaped sequence (\n) to its unescaped version (
).
Whether string literals support escape sequences (e.g. \n). Set by the metaclass based on the tokenizer's STRING_ESCAPES.
Whether byte string literals support escape sequences. Set by the metaclass based on the tokenizer's BYTE_STRING_ESCAPES.
Mapping of an identifier escape char (\) to its escaped version (\\). Set by the metaclass based on the tokenizer's IDENTIFIER_ESCAPES.
137 class JSONPathTokenizer(jsonpath.JSONPathTokenizer): 138 VAR_TOKENS = { 139 *jsonpath.JSONPathTokenizer.VAR_TOKENS, 140 TokenType.DASH, 141 TokenType.NUMBER, 142 }
Inherited Members
- sqlglot.tokens.Tokenizer
- Tokenizer
- BIT_STRINGS
- BYTE_STRINGS
- HEX_STRINGS
- NATIONAL_RAW_STRINGS
- RAW_STRINGS
- HEREDOC_STRINGS
- UNICODE_STRINGS
- UNICODE_IDENTIFIERS
- IDENTIFIERS
- QUOTES
- VAR_SINGLE_TOKENS
- HEREDOC_TAG_IS_IDENTIFIER
- HEREDOC_STRING_ALTERNATIVE
- STRING_ESCAPES_ALLOWED_IN_RAW_STRINGS
- NUMERIC_ESCAPES
- DROP_UNKNOWN_ESCAPES
- NUMERIC_ESCAPES_ARE_BYTES
- LONE_SURROGATE_REPLACEMENT
- NESTED_COMMENTS
- DASH_COMMENT_REQUIRES_BOUNDARY
- COMMENTS_TERMINATE_AT_NEWLINE_ONLY
- UNQUOTED_PATH_TERMINATORS
- HINT_START
- TOKENS_PRECEDING_HINT
- COMMANDS
- COMMAND_PREFIX_TOKENS
- NUMERIC_LITERALS
- COMMENTS
- dialect
- tokenize
- sql
- size
- tokens
144 class Tokenizer(tokens.Tokenizer): 145 NUMERIC_ESCAPES = { 146 "x": (16, 2, 2, 0xFF), 147 "X": (16, 2, 2, 0xFF), 148 "u": (16, 4, 4, 0xFFFF), 149 "U": (16, 8, 8, 0x10FFFF), 150 "0": (8, 3, 3, 0xFF), 151 } 152 DROP_UNKNOWN_ESCAPES = True 153 QUOTES = ["'", '"', '"""', "'''"] 154 COMMENTS = ["--", "#", ("/*", "*/")] 155 IDENTIFIERS = ["`"] 156 IDENTIFIER_ESCAPES = ["\\"] 157 STRING_ESCAPES = ["\\"] 158 159 HEX_STRINGS = [("0x", ""), ("0X", "")] 160 161 BYTE_STRINGS = [(prefix + q, q) for q in t.cast(list[str], QUOTES) for prefix in ("b", "B")] 162 163 RAW_STRINGS = [(prefix + q, q) for q in t.cast(list[str], QUOTES) for prefix in ("r", "R")] 164 165 NESTED_COMMENTS = False 166 167 KEYWORDS = { 168 **tokens.Tokenizer.KEYWORDS, 169 "ANY TYPE": TokenType.VARIANT, 170 "BEGIN": TokenType.COMMAND, 171 "BEGIN TRANSACTION": TokenType.BEGIN, 172 "BYTEINT": TokenType.INT, 173 "BYTES": TokenType.BINARY, 174 "CURRENT_DATETIME": TokenType.CURRENT_DATETIME, 175 "DATETIME": TokenType.TIMESTAMP, 176 "DECLARE": TokenType.DECLARE, 177 "ELSEIF": TokenType.COMMAND, 178 "EXCEPTION": TokenType.COMMAND, 179 "EXPORT": TokenType.EXPORT, 180 "FLOAT64": TokenType.DOUBLE, 181 "LOOP": TokenType.COMMAND, 182 "MODEL": TokenType.MODEL, 183 "RECORD": TokenType.STRUCT, 184 "REPEAT": TokenType.COMMAND, 185 "TIMESTAMP": TokenType.TIMESTAMPTZ, 186 "WHILE": TokenType.COMMAND, 187 } 188 KEYWORDS.pop("ISNULL") 189 KEYWORDS.pop("DIV") 190 KEYWORDS.pop("VALUES") 191 KEYWORDS.pop("/*+")
Inherited Members
- sqlglot.tokens.Tokenizer
- Tokenizer
- SINGLE_TOKENS
- BIT_STRINGS
- NATIONAL_RAW_STRINGS
- HEREDOC_STRINGS
- UNICODE_STRINGS
- UNICODE_IDENTIFIERS
- VAR_SINGLE_TOKENS
- HEREDOC_TAG_IS_IDENTIFIER
- HEREDOC_STRING_ALTERNATIVE
- STRING_ESCAPES_ALLOWED_IN_RAW_STRINGS
- NUMERIC_ESCAPES_ARE_BYTES
- LONE_SURROGATE_REPLACEMENT
- DASH_COMMENT_REQUIRES_BOUNDARY
- COMMENTS_TERMINATE_AT_NEWLINE_ONLY
- UNQUOTED_PATH_TERMINATORS
- HINT_START
- TOKENS_PRECEDING_HINT
- COMMANDS
- COMMAND_PREFIX_TOKENS
- NUMERIC_LITERALS
- NUMBERS_CAN_HAVE_DECIMALS
- dialect
- tokenize
- sql
- size
- tokens