summaryrefslogtreecommitdiffstats
path: root/sqlglot/generator.py
diff options
context:
space:
mode:
Diffstat (limited to 'sqlglot/generator.py')
-rw-r--r--sqlglot/generator.py56
1 files changed, 54 insertions, 2 deletions
diff --git a/sqlglot/generator.py b/sqlglot/generator.py
index 1074e9a..399b48b 100644
--- a/sqlglot/generator.py
+++ b/sqlglot/generator.py
@@ -193,8 +193,10 @@ class Generator:
exp.DataType.Type.NVARCHAR: "VARCHAR",
exp.DataType.Type.MEDIUMTEXT: "TEXT",
exp.DataType.Type.LONGTEXT: "TEXT",
+ exp.DataType.Type.TINYTEXT: "TEXT",
exp.DataType.Type.MEDIUMBLOB: "BLOB",
exp.DataType.Type.LONGBLOB: "BLOB",
+ exp.DataType.Type.TINYBLOB: "BLOB",
exp.DataType.Type.INET: "INET",
}
@@ -2021,6 +2023,9 @@ class Generator:
def jsonkeyvalue_sql(self, expression: exp.JSONKeyValue) -> str:
return f"{self.sql(expression, 'this')}: {self.sql(expression, 'expression')}"
+ def formatjson_sql(self, expression: exp.FormatJson) -> str:
+ return f"{self.sql(expression, 'this')} FORMAT JSON"
+
def jsonobject_sql(self, expression: exp.JSONObject) -> str:
null_handling = expression.args.get("null_handling")
null_handling = f" {null_handling}" if null_handling else ""
@@ -2031,13 +2036,57 @@ class Generator:
unique_keys = ""
return_type = self.sql(expression, "return_type")
return_type = f" RETURNING {return_type}" if return_type else ""
- format_json = " FORMAT JSON" if expression.args.get("format_json") else ""
encoding = self.sql(expression, "encoding")
encoding = f" ENCODING {encoding}" if encoding else ""
return self.func(
"JSON_OBJECT",
*expression.expressions,
- suffix=f"{null_handling}{unique_keys}{return_type}{format_json}{encoding})",
+ suffix=f"{null_handling}{unique_keys}{return_type}{encoding})",
+ )
+
+ def jsonarray_sql(self, expression: exp.JSONArray) -> str:
+ null_handling = expression.args.get("null_handling")
+ null_handling = f" {null_handling}" if null_handling else ""
+ return_type = self.sql(expression, "return_type")
+ return_type = f" RETURNING {return_type}" if return_type else ""
+ strict = " STRICT" if expression.args.get("strict") else ""
+ return self.func(
+ "JSON_ARRAY", *expression.expressions, suffix=f"{null_handling}{return_type}{strict})"
+ )
+
+ def jsonarrayagg_sql(self, expression: exp.JSONArrayAgg) -> str:
+ this = self.sql(expression, "this")
+ order = self.sql(expression, "order")
+ null_handling = expression.args.get("null_handling")
+ null_handling = f" {null_handling}" if null_handling else ""
+ return_type = self.sql(expression, "return_type")
+ return_type = f" RETURNING {return_type}" if return_type else ""
+ strict = " STRICT" if expression.args.get("strict") else ""
+ return self.func(
+ "JSON_ARRAYAGG",
+ this,
+ suffix=f"{order}{null_handling}{return_type}{strict})",
+ )
+
+ def jsoncolumndef_sql(self, expression: exp.JSONColumnDef) -> str:
+ this = self.sql(expression, "this")
+ kind = self.sql(expression, "kind")
+ kind = f" {kind}" if kind else ""
+ path = self.sql(expression, "path")
+ path = f" PATH {path}" if path else ""
+ return f"{this}{kind}{path}"
+
+ def jsontable_sql(self, expression: exp.JSONTable) -> str:
+ this = self.sql(expression, "this")
+ path = self.sql(expression, "path")
+ path = f", {path}" if path else ""
+ error_handling = expression.args.get("error_handling")
+ error_handling = f" {error_handling}" if error_handling else ""
+ empty_handling = expression.args.get("empty_handling")
+ empty_handling = f" {empty_handling}" if empty_handling else ""
+ columns = f" COLUMNS ({self.expressions(expression, skip_first=True)})"
+ return self.func(
+ "JSON_TABLE", this, suffix=f"{path}{error_handling}{empty_handling}{columns})"
)
def openjsoncolumndef_sql(self, expression: exp.OpenJSONColumnDef) -> str:
@@ -2722,6 +2771,9 @@ class Generator:
condition = f" IF {condition}" if condition else ""
return f"{this} FOR {expr} IN {iterator}{condition}"
+ def columnprefix_sql(self, expression: exp.ColumnPrefix) -> str:
+ return f"{self.sql(expression, 'this')}({self.sql(expression, 'expression')})"
+
def cached_generator(
cache: t.Optional[t.Dict[int, str]] = None