diff options
Diffstat (limited to 'sqlglot/dialects/sqlite.py')
-rw-r--r-- | sqlglot/dialects/sqlite.py | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/sqlglot/dialects/sqlite.py b/sqlglot/dialects/sqlite.py index 244a96e..b292c81 100644 --- a/sqlglot/dialects/sqlite.py +++ b/sqlglot/dialects/sqlite.py @@ -7,7 +7,6 @@ from sqlglot.dialects.dialect import ( Dialect, NormalizationStrategy, any_value_to_max_sql, - arrow_json_extract_scalar_sql, arrow_json_extract_sql, concat_to_dpipe_sql, count_if_to_sum, @@ -28,6 +27,12 @@ def _date_add_sql(self: SQLite.Generator, expression: exp.DateAdd) -> str: return self.func("DATE", expression.this, modifier) +def _json_extract_sql(self: SQLite.Generator, expression: exp.JSONExtract) -> str: + if expression.expressions: + return self.function_fallback_sql(expression) + return arrow_json_extract_sql(self, expression) + + def _transform_create(expression: exp.Expression) -> exp.Expression: """Move primary key to a column and enforce auto_increment on primary keys.""" schema = expression.this @@ -85,6 +90,14 @@ class SQLite(Dialect): TABLE_HINTS = False QUERY_HINTS = False NVL2_SUPPORTED = False + JSON_PATH_BRACKETED_KEY_SUPPORTED = False + SUPPORTS_CREATE_TABLE_LIKE = False + + SUPPORTED_JSON_PATH_PARTS = { + exp.JSONPathKey, + exp.JSONPathRoot, + exp.JSONPathSubscript, + } TYPE_MAPPING = { **generator.Generator.TYPE_MAPPING, @@ -120,10 +133,8 @@ class SQLite(Dialect): exp.DateAdd: _date_add_sql, exp.DateStrToDate: lambda self, e: self.sql(e, "this"), exp.ILike: no_ilike_sql, - exp.JSONExtract: arrow_json_extract_sql, - exp.JSONExtractScalar: arrow_json_extract_scalar_sql, - exp.JSONBExtract: arrow_json_extract_sql, - exp.JSONBExtractScalar: arrow_json_extract_scalar_sql, + exp.JSONExtract: _json_extract_sql, + exp.JSONExtractScalar: arrow_json_extract_sql, exp.Levenshtein: rename_func("EDITDIST3"), exp.LogicalOr: rename_func("MAX"), exp.LogicalAnd: rename_func("MIN"), @@ -141,11 +152,18 @@ class SQLite(Dialect): exp.TryCast: no_trycast_sql, } + # SQLite doesn't generally support CREATE TABLE .. properties + # https://www.sqlite.org/lang_createtable.html PROPERTIES_LOCATION = { - k: exp.Properties.Location.UNSUPPORTED - for k, v in generator.Generator.PROPERTIES_LOCATION.items() + prop: exp.Properties.Location.UNSUPPORTED + for prop in generator.Generator.PROPERTIES_LOCATION } + # There are a few exceptions (e.g. temporary tables) which are supported or + # can be transpiled to SQLite, so we explicitly override them accordingly + PROPERTIES_LOCATION[exp.LikeProperty] = exp.Properties.Location.POST_SCHEMA + PROPERTIES_LOCATION[exp.TemporaryProperty] = exp.Properties.Location.POST_CREATE + LIMIT_FETCH = "LIMIT" def cast_sql(self, expression: exp.Cast, safe_prefix: t.Optional[str] = None) -> str: |