We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Teradata to Databricks transpilation issue
When working on Teradata to Databricks conversion i ran into a issue where a command like "Database databasename" which is equvalent to "USE Databasename" on Databricks side is not getting tranpiled correctly. The final output still shows the original command.


**Sample code** below
```
sql="""
	DATABASE tduser;
"""

try:
    new_query = sqlglot.transpile(sql, read='teradata', write='databricks', pretty=True)[0]
    print(new_query)
except sqlglot.errors.ParseError as error:
    print(traceback.format_exc())
    print(error.errors)
```
**Expected output:**
USE tduser

**Official Documentation**
https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-ddl-usedb.html


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `sqlglot/dialects/teradata.py`
Content:
```
1 from __future__ import annotations
2 
3 import typing as t
4 
5 from sqlglot import exp, generator, parser, tokens, transforms
6 from sqlglot.dialects.dialect import Dialect, max_or_greatest, min_or_least
7 from sqlglot.tokens import TokenType
8 
9 
10 class Teradata(Dialect):
11     TIME_MAPPING = {
12         "Y": "%Y",
13         "YYYY": "%Y",
14         "YY": "%y",
15         "MMMM": "%B",
16         "MMM": "%b",
17         "DD": "%d",
18         "D": "%-d",
19         "HH": "%H",
20         "H": "%-H",
21         "MM": "%M",
22         "M": "%-M",
23         "SS": "%S",
24         "S": "%-S",
25         "SSSSSS": "%f",
26         "E": "%a",
27         "EE": "%a",
28         "EEE": "%a",
29         "EEEE": "%A",
30     }
31 
32     class Tokenizer(tokens.Tokenizer):
33         # https://docs.teradata.com/r/Teradata-Database-SQL-Functions-Operators-Expressions-and-Predicates/March-2017/Comparison-Operators-and-Functions/Comparison-Operators/ANSI-Compliance
34         KEYWORDS = {
35             **tokens.Tokenizer.KEYWORDS,
36             "^=": TokenType.NEQ,
37             "BYTEINT": TokenType.SMALLINT,
38             "COLLECT": TokenType.COMMAND,
39             "GE": TokenType.GTE,
40             "GT": TokenType.GT,
41             "HELP": TokenType.COMMAND,
42             "INS": TokenType.INSERT,
43             "LE": TokenType.LTE,
44             "LT": TokenType.LT,
45             "MOD": TokenType.MOD,
46             "NE": TokenType.NEQ,
47             "NOT=": TokenType.NEQ,
48             "SEL": TokenType.SELECT,
49             "ST_GEOMETRY": TokenType.GEOMETRY,
50             "TOP": TokenType.TOP,
51         }
52 
53         # Teradata does not support % as a modulo operator
54         SINGLE_TOKENS = {**tokens.Tokenizer.SINGLE_TOKENS}
55         SINGLE_TOKENS.pop("%")
56 
57     class Parser(parser.Parser):
58         CHARSET_TRANSLATORS = {
59             "GRAPHIC_TO_KANJISJIS",
60             "GRAPHIC_TO_LATIN",
61             "GRAPHIC_TO_UNICODE",
62             "GRAPHIC_TO_UNICODE_PadSpace",
63             "KANJI1_KanjiEBCDIC_TO_UNICODE",
64             "KANJI1_KanjiEUC_TO_UNICODE",
65             "KANJI1_KANJISJIS_TO_UNICODE",
66             "KANJI1_SBC_TO_UNICODE",
67             "KANJISJIS_TO_GRAPHIC",
68             "KANJISJIS_TO_LATIN",
69             "KANJISJIS_TO_UNICODE",
70             "LATIN_TO_GRAPHIC",
71             "LATIN_TO_KANJISJIS",
72             "LATIN_TO_UNICODE",
73             "LOCALE_TO_UNICODE",
74             "UNICODE_TO_GRAPHIC",
75             "UNICODE_TO_GRAPHIC_PadGraphic",
76             "UNICODE_TO_GRAPHIC_VarGraphic",
77             "UNICODE_TO_KANJI1_KanjiEBCDIC",
78             "UNICODE_TO_KANJI1_KanjiEUC",
79             "UNICODE_TO_KANJI1_KANJISJIS",
80             "UNICODE_TO_KANJI1_SBC",
81             "UNICODE_TO_KANJISJIS",
82             "UNICODE_TO_LATIN",
83             "UNICODE_TO_LOCALE",
84             "UNICODE_TO_UNICODE_FoldSpace",
85             "UNICODE_TO_UNICODE_Fullwidth",
86             "UNICODE_TO_UNICODE_Halfwidth",
87             "UNICODE_TO_UNICODE_NFC",
88             "UNICODE_TO_UNICODE_NFD",
89             "UNICODE_TO_UNICODE_NFKC",
90             "UNICODE_TO_UNICODE_NFKD",
91         }
92 
93         FUNC_TOKENS = {*parser.Parser.FUNC_TOKENS}
94         FUNC_TOKENS.remove(TokenType.REPLACE)
95 
96         STATEMENT_PARSERS = {
97             **parser.Parser.STATEMENT_PARSERS,
98             TokenType.REPLACE: lambda self: self._parse_create(),
99         }
100 
101         FUNCTION_PARSERS = {
102             **parser.Parser.FUNCTION_PARSERS,
103             "RANGE_N": lambda self: self._parse_rangen(),
104             "TRANSLATE": lambda self: self._parse_translate(self.STRICT_CAST),
105         }
106 
107         def _parse_translate(self, strict: bool) -> exp.Expression:
108             this = self._parse_conjunction()
109 
110             if not self._match(TokenType.USING):
111                 self.raise_error("Expected USING in TRANSLATE")
112 
113             if self._match_texts(self.CHARSET_TRANSLATORS):
114                 charset_split = self._prev.text.split("_TO_")
115                 to = self.expression(exp.CharacterSet, this=charset_split[1])
116             else:
117                 self.raise_error("Expected a character set translator after USING in TRANSLATE")
118 
119             return self.expression(exp.Cast if strict else exp.TryCast, this=this, to=to)
120 
121         # FROM before SET in Teradata UPDATE syntax
122         # https://docs.teradata.com/r/Enterprise_IntelliFlex_VMware/Teradata-VantageTM-SQL-Data-Manipulation-Language-17.20/Statement-Syntax/UPDATE/UPDATE-Syntax-Basic-Form-FROM-Clause
123         def _parse_update(self) -> exp.Update:
124             return self.expression(
125                 exp.Update,
126                 **{  # type: ignore
127                     "this": self._parse_table(alias_tokens=self.UPDATE_ALIAS_TOKENS),
128                     "from": self._parse_from(joins=True),
129                     "expressions": self._match(TokenType.SET)
130                     and self._parse_csv(self._parse_equality),
131                     "where": self._parse_where(),
132                 },
133             )
134 
135         def _parse_rangen(self):
136             this = self._parse_id_var()
137             self._match(TokenType.BETWEEN)
138 
139             expressions = self._parse_csv(self._parse_conjunction)
140             each = self._match_text_seq("EACH") and self._parse_conjunction()
141 
142             return self.expression(exp.RangeN, this=this, expressions=expressions, each=each)
143 
144     class Generator(generator.Generator):
145         JOIN_HINTS = False
146         TABLE_HINTS = False
147         QUERY_HINTS = False
148 
149         TYPE_MAPPING = {
150             **generator.Generator.TYPE_MAPPING,
151             exp.DataType.Type.GEOMETRY: "ST_GEOMETRY",
152         }
153 
154         PROPERTIES_LOCATION = {
155             **generator.Generator.PROPERTIES_LOCATION,
156             exp.OnCommitProperty: exp.Properties.Location.POST_INDEX,
157             exp.PartitionedByProperty: exp.Properties.Location.POST_EXPRESSION,
158             exp.StabilityProperty: exp.Properties.Location.POST_CREATE,
159         }
160 
161         TRANSFORMS = {
162             **generator.Generator.TRANSFORMS,
163             exp.Max: max_or_greatest,
164             exp.Min: min_or_least,
165             exp.Select: transforms.preprocess([transforms.eliminate_distinct_on]),
166             exp.StrToDate: lambda self, e: f"CAST({self.sql(e, 'this')} AS DATE FORMAT {self.format_time(e)})",
167             exp.ToChar: lambda self, e: self.function_fallback_sql(e),
168         }
169 
170         def partitionedbyproperty_sql(self, expression: exp.PartitionedByProperty) -> str:
171             return f"PARTITION BY {self.sql(expression, 'this')}"
172 
173         # FROM before SET in Teradata UPDATE syntax
174         # https://docs.teradata.com/r/Enterprise_IntelliFlex_VMware/Teradata-VantageTM-SQL-Data-Manipulation-Language-17.20/Statement-Syntax/UPDATE/UPDATE-Syntax-Basic-Form-FROM-Clause
175         def update_sql(self, expression: exp.Update) -> str:
176             this = self.sql(expression, "this")
177             from_sql = self.sql(expression, "from")
178             set_sql = self.expressions(expression, flat=True)
179             where_sql = self.sql(expression, "where")
180             sql = f"UPDATE {this}{from_sql} SET {set_sql}{where_sql}"
181             return self.prepend_ctes(expression, sql)
182 
183         def mod_sql(self, expression: exp.Mod) -> str:
184             return self.binary(expression, "MOD")
185 
186         def datatype_sql(self, expression: exp.DataType) -> str:
187             type_sql = super().datatype_sql(expression)
188             prefix_sql = expression.args.get("prefix")
189             return f"SYSUDTLIB.{type_sql}" if prefix_sql else type_sql
190 
191         def rangen_sql(self, expression: exp.RangeN) -> str:
192             this = self.sql(expression, "this")
193             expressions_sql = self.expressions(expression)
194             each_sql = self.sql(expression, "each")
195             each_sql = f" EACH {each_sql}" if each_sql else ""
196 
197             return f"RANGE_N({this} BETWEEN {expressions_sql}{each_sql})"
198 
199         def createable_sql(self, expression: exp.Create, locations: t.DefaultDict) -> str:
200             kind = self.sql(expression, "kind").upper()
201             if kind == "TABLE" and locations.get(exp.Properties.Location.POST_NAME):
202                 this_name = self.sql(expression.this, "this")
203                 this_properties = self.properties(
204                     exp.Properties(expressions=locations[exp.Properties.Location.POST_NAME]),
205                     wrapped=False,
206                     prefix=",",
207                 )
208                 this_schema = self.schema_columns_sql(expression.this)
209                 return f"{this_name}{this_properties}{self.sep()}{this_schema}"
210 
211             return super().createable_sql(expression, locations)
212
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/sqlglot/dialects/teradata.py b/sqlglot/dialects/teradata.py
--- a/sqlglot/dialects/teradata.py
+++ b/sqlglot/dialects/teradata.py
@@ -95,6 +95,9 @@
 
         STATEMENT_PARSERS = {
             **parser.Parser.STATEMENT_PARSERS,
+            TokenType.DATABASE: lambda self: self.expression(
+                exp.Use, this=self._parse_table(schema=False)
+            ),
             TokenType.REPLACE: lambda self: self._parse_create(),
         }
 
@@ -165,6 +168,7 @@
             exp.Select: transforms.preprocess([transforms.eliminate_distinct_on]),
             exp.StrToDate: lambda self, e: f"CAST({self.sql(e, 'this')} AS DATE FORMAT {self.format_time(e)})",
             exp.ToChar: lambda self, e: self.function_fallback_sql(e),
+            exp.Use: lambda self, e: f"DATABASE {self.sql(e, 'this')}",
         }
 
         def partitionedbyproperty_sql(self, expression: exp.PartitionedByProperty) -> str:

{"golden_diff": "diff --git a/sqlglot/dialects/teradata.py b/sqlglot/dialects/teradata.py\n--- a/sqlglot/dialects/teradata.py\n+++ b/sqlglot/dialects/teradata.py\n@@ -95,6 +95,9 @@\n \n         STATEMENT_PARSERS = {\n             **parser.Parser.STATEMENT_PARSERS,\n+            TokenType.DATABASE: lambda self: self.expression(\n+                exp.Use, this=self._parse_table(schema=False)\n+            ),\n             TokenType.REPLACE: lambda self: self._parse_create(),\n         }\n \n@@ -165,6 +168,7 @@\n             exp.Select: transforms.preprocess([transforms.eliminate_distinct_on]),\n             exp.StrToDate: lambda self, e: f\"CAST({self.sql(e, 'this')} AS DATE FORMAT {self.format_time(e)})\",\n             exp.ToChar: lambda self, e: self.function_fallback_sql(e),\n+            exp.Use: lambda self, e: f\"DATABASE {self.sql(e, 'this')}\",\n         }\n \n         def partitionedbyproperty_sql(self, expression: exp.PartitionedByProperty) -> str:\n", "issue": "Teradata to Databricks transpilation issue\nWhen working on Teradata to Databricks conversion i ran into a issue where a command like \"Database databasename\" which is equvalent to \"USE Databasename\" on Databricks side is not getting tranpiled correctly. The final output still shows the original command.\r\n\r\n\r\n**Sample code** below\r\n```\r\nsql=\"\"\"\r\n\tDATABASE tduser;\r\n\"\"\"\r\n\r\ntry:\r\n    new_query = sqlglot.transpile(sql, read='teradata', write='databricks', pretty=True)[0]\r\n    print(new_query)\r\nexcept sqlglot.errors.ParseError as error:\r\n    print(traceback.format_exc())\r\n    print(error.errors)\r\n```\r\n**Expected output:**\r\nUSE tduser\r\n\r\n**Official Documentation**\r\nhttps://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-ddl-usedb.html\r\n\n", "before_files": [{"content": "from __future__ import annotations\n\nimport typing as t\n\nfrom sqlglot import exp, generator, parser, tokens, transforms\nfrom sqlglot.dialects.dialect import Dialect, max_or_greatest, min_or_least\nfrom sqlglot.tokens import TokenType\n\n\nclass Teradata(Dialect):\n    TIME_MAPPING = {\n        \"Y\": \"%Y\",\n        \"YYYY\": \"%Y\",\n        \"YY\": \"%y\",\n        \"MMMM\": \"%B\",\n        \"MMM\": \"%b\",\n        \"DD\": \"%d\",\n        \"D\": \"%-d\",\n        \"HH\": \"%H\",\n        \"H\": \"%-H\",\n        \"MM\": \"%M\",\n        \"M\": \"%-M\",\n        \"SS\": \"%S\",\n        \"S\": \"%-S\",\n        \"SSSSSS\": \"%f\",\n        \"E\": \"%a\",\n        \"EE\": \"%a\",\n        \"EEE\": \"%a\",\n        \"EEEE\": \"%A\",\n    }\n\n    class Tokenizer(tokens.Tokenizer):\n        # https://docs.teradata.com/r/Teradata-Database-SQL-Functions-Operators-Expressions-and-Predicates/March-2017/Comparison-Operators-and-Functions/Comparison-Operators/ANSI-Compliance\n        KEYWORDS = {\n            **tokens.Tokenizer.KEYWORDS,\n            \"^=\": TokenType.NEQ,\n            \"BYTEINT\": TokenType.SMALLINT,\n            \"COLLECT\": TokenType.COMMAND,\n            \"GE\": TokenType.GTE,\n            \"GT\": TokenType.GT,\n            \"HELP\": TokenType.COMMAND,\n            \"INS\": TokenType.INSERT,\n            \"LE\": TokenType.LTE,\n            \"LT\": TokenType.LT,\n            \"MOD\": TokenType.MOD,\n            \"NE\": TokenType.NEQ,\n            \"NOT=\": TokenType.NEQ,\n            \"SEL\": TokenType.SELECT,\n            \"ST_GEOMETRY\": TokenType.GEOMETRY,\n            \"TOP\": TokenType.TOP,\n        }\n\n        # Teradata does not support % as a modulo operator\n        SINGLE_TOKENS = {**tokens.Tokenizer.SINGLE_TOKENS}\n        SINGLE_TOKENS.pop(\"%\")\n\n    class Parser(parser.Parser):\n        CHARSET_TRANSLATORS = {\n            \"GRAPHIC_TO_KANJISJIS\",\n            \"GRAPHIC_TO_LATIN\",\n            \"GRAPHIC_TO_UNICODE\",\n            \"GRAPHIC_TO_UNICODE_PadSpace\",\n            \"KANJI1_KanjiEBCDIC_TO_UNICODE\",\n            \"KANJI1_KanjiEUC_TO_UNICODE\",\n            \"KANJI1_KANJISJIS_TO_UNICODE\",\n            \"KANJI1_SBC_TO_UNICODE\",\n            \"KANJISJIS_TO_GRAPHIC\",\n            \"KANJISJIS_TO_LATIN\",\n            \"KANJISJIS_TO_UNICODE\",\n            \"LATIN_TO_GRAPHIC\",\n            \"LATIN_TO_KANJISJIS\",\n            \"LATIN_TO_UNICODE\",\n            \"LOCALE_TO_UNICODE\",\n            \"UNICODE_TO_GRAPHIC\",\n            \"UNICODE_TO_GRAPHIC_PadGraphic\",\n            \"UNICODE_TO_GRAPHIC_VarGraphic\",\n            \"UNICODE_TO_KANJI1_KanjiEBCDIC\",\n            \"UNICODE_TO_KANJI1_KanjiEUC\",\n            \"UNICODE_TO_KANJI1_KANJISJIS\",\n            \"UNICODE_TO_KANJI1_SBC\",\n            \"UNICODE_TO_KANJISJIS\",\n            \"UNICODE_TO_LATIN\",\n            \"UNICODE_TO_LOCALE\",\n            \"UNICODE_TO_UNICODE_FoldSpace\",\n            \"UNICODE_TO_UNICODE_Fullwidth\",\n            \"UNICODE_TO_UNICODE_Halfwidth\",\n            \"UNICODE_TO_UNICODE_NFC\",\n            \"UNICODE_TO_UNICODE_NFD\",\n            \"UNICODE_TO_UNICODE_NFKC\",\n            \"UNICODE_TO_UNICODE_NFKD\",\n        }\n\n        FUNC_TOKENS = {*parser.Parser.FUNC_TOKENS}\n        FUNC_TOKENS.remove(TokenType.REPLACE)\n\n        STATEMENT_PARSERS = {\n            **parser.Parser.STATEMENT_PARSERS,\n            TokenType.REPLACE: lambda self: self._parse_create(),\n        }\n\n        FUNCTION_PARSERS = {\n            **parser.Parser.FUNCTION_PARSERS,\n            \"RANGE_N\": lambda self: self._parse_rangen(),\n            \"TRANSLATE\": lambda self: self._parse_translate(self.STRICT_CAST),\n        }\n\n        def _parse_translate(self, strict: bool) -> exp.Expression:\n            this = self._parse_conjunction()\n\n            if not self._match(TokenType.USING):\n                self.raise_error(\"Expected USING in TRANSLATE\")\n\n            if self._match_texts(self.CHARSET_TRANSLATORS):\n                charset_split = self._prev.text.split(\"_TO_\")\n                to = self.expression(exp.CharacterSet, this=charset_split[1])\n            else:\n                self.raise_error(\"Expected a character set translator after USING in TRANSLATE\")\n\n            return self.expression(exp.Cast if strict else exp.TryCast, this=this, to=to)\n\n        # FROM before SET in Teradata UPDATE syntax\n        # https://docs.teradata.com/r/Enterprise_IntelliFlex_VMware/Teradata-VantageTM-SQL-Data-Manipulation-Language-17.20/Statement-Syntax/UPDATE/UPDATE-Syntax-Basic-Form-FROM-Clause\n        def _parse_update(self) -> exp.Update:\n            return self.expression(\n                exp.Update,\n                **{  # type: ignore\n                    \"this\": self._parse_table(alias_tokens=self.UPDATE_ALIAS_TOKENS),\n                    \"from\": self._parse_from(joins=True),\n                    \"expressions\": self._match(TokenType.SET)\n                    and self._parse_csv(self._parse_equality),\n                    \"where\": self._parse_where(),\n                },\n            )\n\n        def _parse_rangen(self):\n            this = self._parse_id_var()\n            self._match(TokenType.BETWEEN)\n\n            expressions = self._parse_csv(self._parse_conjunction)\n            each = self._match_text_seq(\"EACH\") and self._parse_conjunction()\n\n            return self.expression(exp.RangeN, this=this, expressions=expressions, each=each)\n\n    class Generator(generator.Generator):\n        JOIN_HINTS = False\n        TABLE_HINTS = False\n        QUERY_HINTS = False\n\n        TYPE_MAPPING = {\n            **generator.Generator.TYPE_MAPPING,\n            exp.DataType.Type.GEOMETRY: \"ST_GEOMETRY\",\n        }\n\n        PROPERTIES_LOCATION = {\n            **generator.Generator.PROPERTIES_LOCATION,\n            exp.OnCommitProperty: exp.Properties.Location.POST_INDEX,\n            exp.PartitionedByProperty: exp.Properties.Location.POST_EXPRESSION,\n            exp.StabilityProperty: exp.Properties.Location.POST_CREATE,\n        }\n\n        TRANSFORMS = {\n            **generator.Generator.TRANSFORMS,\n            exp.Max: max_or_greatest,\n            exp.Min: min_or_least,\n            exp.Select: transforms.preprocess([transforms.eliminate_distinct_on]),\n            exp.StrToDate: lambda self, e: f\"CAST({self.sql(e, 'this')} AS DATE FORMAT {self.format_time(e)})\",\n            exp.ToChar: lambda self, e: self.function_fallback_sql(e),\n        }\n\n        def partitionedbyproperty_sql(self, expression: exp.PartitionedByProperty) -> str:\n            return f\"PARTITION BY {self.sql(expression, 'this')}\"\n\n        # FROM before SET in Teradata UPDATE syntax\n        # https://docs.teradata.com/r/Enterprise_IntelliFlex_VMware/Teradata-VantageTM-SQL-Data-Manipulation-Language-17.20/Statement-Syntax/UPDATE/UPDATE-Syntax-Basic-Form-FROM-Clause\n        def update_sql(self, expression: exp.Update) -> str:\n            this = self.sql(expression, \"this\")\n            from_sql = self.sql(expression, \"from\")\n            set_sql = self.expressions(expression, flat=True)\n            where_sql = self.sql(expression, \"where\")\n            sql = f\"UPDATE {this}{from_sql} SET {set_sql}{where_sql}\"\n            return self.prepend_ctes(expression, sql)\n\n        def mod_sql(self, expression: exp.Mod) -> str:\n            return self.binary(expression, \"MOD\")\n\n        def datatype_sql(self, expression: exp.DataType) -> str:\n            type_sql = super().datatype_sql(expression)\n            prefix_sql = expression.args.get(\"prefix\")\n            return f\"SYSUDTLIB.{type_sql}\" if prefix_sql else type_sql\n\n        def rangen_sql(self, expression: exp.RangeN) -> str:\n            this = self.sql(expression, \"this\")\n            expressions_sql = self.expressions(expression)\n            each_sql = self.sql(expression, \"each\")\n            each_sql = f\" EACH {each_sql}\" if each_sql else \"\"\n\n            return f\"RANGE_N({this} BETWEEN {expressions_sql}{each_sql})\"\n\n        def createable_sql(self, expression: exp.Create, locations: t.DefaultDict) -> str:\n            kind = self.sql(expression, \"kind\").upper()\n            if kind == \"TABLE\" and locations.get(exp.Properties.Location.POST_NAME):\n                this_name = self.sql(expression.this, \"this\")\n                this_properties = self.properties(\n                    exp.Properties(expressions=locations[exp.Properties.Location.POST_NAME]),\n                    wrapped=False,\n                    prefix=\",\",\n                )\n                this_schema = self.schema_columns_sql(expression.this)\n                return f\"{this_name}{this_properties}{self.sep()}{this_schema}\"\n\n            return super().createable_sql(expression, locations)\n", "path": "sqlglot/dialects/teradata.py"}], "after_files": [{"content": "from __future__ import annotations\n\nimport typing as t\n\nfrom sqlglot import exp, generator, parser, tokens, transforms\nfrom sqlglot.dialects.dialect import Dialect, max_or_greatest, min_or_least\nfrom sqlglot.tokens import TokenType\n\n\nclass Teradata(Dialect):\n    TIME_MAPPING = {\n        \"Y\": \"%Y\",\n        \"YYYY\": \"%Y\",\n        \"YY\": \"%y\",\n        \"MMMM\": \"%B\",\n        \"MMM\": \"%b\",\n        \"DD\": \"%d\",\n        \"D\": \"%-d\",\n        \"HH\": \"%H\",\n        \"H\": \"%-H\",\n        \"MM\": \"%M\",\n        \"M\": \"%-M\",\n        \"SS\": \"%S\",\n        \"S\": \"%-S\",\n        \"SSSSSS\": \"%f\",\n        \"E\": \"%a\",\n        \"EE\": \"%a\",\n        \"EEE\": \"%a\",\n        \"EEEE\": \"%A\",\n    }\n\n    class Tokenizer(tokens.Tokenizer):\n        # https://docs.teradata.com/r/Teradata-Database-SQL-Functions-Operators-Expressions-and-Predicates/March-2017/Comparison-Operators-and-Functions/Comparison-Operators/ANSI-Compliance\n        KEYWORDS = {\n            **tokens.Tokenizer.KEYWORDS,\n            \"^=\": TokenType.NEQ,\n            \"BYTEINT\": TokenType.SMALLINT,\n            \"COLLECT\": TokenType.COMMAND,\n            \"GE\": TokenType.GTE,\n            \"GT\": TokenType.GT,\n            \"HELP\": TokenType.COMMAND,\n            \"INS\": TokenType.INSERT,\n            \"LE\": TokenType.LTE,\n            \"LT\": TokenType.LT,\n            \"MOD\": TokenType.MOD,\n            \"NE\": TokenType.NEQ,\n            \"NOT=\": TokenType.NEQ,\n            \"SEL\": TokenType.SELECT,\n            \"ST_GEOMETRY\": TokenType.GEOMETRY,\n            \"TOP\": TokenType.TOP,\n        }\n\n        # Teradata does not support % as a modulo operator\n        SINGLE_TOKENS = {**tokens.Tokenizer.SINGLE_TOKENS}\n        SINGLE_TOKENS.pop(\"%\")\n\n    class Parser(parser.Parser):\n        CHARSET_TRANSLATORS = {\n            \"GRAPHIC_TO_KANJISJIS\",\n            \"GRAPHIC_TO_LATIN\",\n            \"GRAPHIC_TO_UNICODE\",\n            \"GRAPHIC_TO_UNICODE_PadSpace\",\n            \"KANJI1_KanjiEBCDIC_TO_UNICODE\",\n            \"KANJI1_KanjiEUC_TO_UNICODE\",\n            \"KANJI1_KANJISJIS_TO_UNICODE\",\n            \"KANJI1_SBC_TO_UNICODE\",\n            \"KANJISJIS_TO_GRAPHIC\",\n            \"KANJISJIS_TO_LATIN\",\n            \"KANJISJIS_TO_UNICODE\",\n            \"LATIN_TO_GRAPHIC\",\n            \"LATIN_TO_KANJISJIS\",\n            \"LATIN_TO_UNICODE\",\n            \"LOCALE_TO_UNICODE\",\n            \"UNICODE_TO_GRAPHIC\",\n            \"UNICODE_TO_GRAPHIC_PadGraphic\",\n            \"UNICODE_TO_GRAPHIC_VarGraphic\",\n            \"UNICODE_TO_KANJI1_KanjiEBCDIC\",\n            \"UNICODE_TO_KANJI1_KanjiEUC\",\n            \"UNICODE_TO_KANJI1_KANJISJIS\",\n            \"UNICODE_TO_KANJI1_SBC\",\n            \"UNICODE_TO_KANJISJIS\",\n            \"UNICODE_TO_LATIN\",\n            \"UNICODE_TO_LOCALE\",\n            \"UNICODE_TO_UNICODE_FoldSpace\",\n            \"UNICODE_TO_UNICODE_Fullwidth\",\n            \"UNICODE_TO_UNICODE_Halfwidth\",\n            \"UNICODE_TO_UNICODE_NFC\",\n            \"UNICODE_TO_UNICODE_NFD\",\n            \"UNICODE_TO_UNICODE_NFKC\",\n            \"UNICODE_TO_UNICODE_NFKD\",\n        }\n\n        FUNC_TOKENS = {*parser.Parser.FUNC_TOKENS}\n        FUNC_TOKENS.remove(TokenType.REPLACE)\n\n        STATEMENT_PARSERS = {\n            **parser.Parser.STATEMENT_PARSERS,\n            TokenType.DATABASE: lambda self: self.expression(\n                exp.Use, this=self._parse_table(schema=False)\n            ),\n            TokenType.REPLACE: lambda self: self._parse_create(),\n        }\n\n        FUNCTION_PARSERS = {\n            **parser.Parser.FUNCTION_PARSERS,\n            \"RANGE_N\": lambda self: self._parse_rangen(),\n            \"TRANSLATE\": lambda self: self._parse_translate(self.STRICT_CAST),\n        }\n\n        def _parse_translate(self, strict: bool) -> exp.Expression:\n            this = self._parse_conjunction()\n\n            if not self._match(TokenType.USING):\n                self.raise_error(\"Expected USING in TRANSLATE\")\n\n            if self._match_texts(self.CHARSET_TRANSLATORS):\n                charset_split = self._prev.text.split(\"_TO_\")\n                to = self.expression(exp.CharacterSet, this=charset_split[1])\n            else:\n                self.raise_error(\"Expected a character set translator after USING in TRANSLATE\")\n\n            return self.expression(exp.Cast if strict else exp.TryCast, this=this, to=to)\n\n        # FROM before SET in Teradata UPDATE syntax\n        # https://docs.teradata.com/r/Enterprise_IntelliFlex_VMware/Teradata-VantageTM-SQL-Data-Manipulation-Language-17.20/Statement-Syntax/UPDATE/UPDATE-Syntax-Basic-Form-FROM-Clause\n        def _parse_update(self) -> exp.Update:\n            return self.expression(\n                exp.Update,\n                **{  # type: ignore\n                    \"this\": self._parse_table(alias_tokens=self.UPDATE_ALIAS_TOKENS),\n                    \"from\": self._parse_from(joins=True),\n                    \"expressions\": self._match(TokenType.SET)\n                    and self._parse_csv(self._parse_equality),\n                    \"where\": self._parse_where(),\n                },\n            )\n\n        def _parse_rangen(self):\n            this = self._parse_id_var()\n            self._match(TokenType.BETWEEN)\n\n            expressions = self._parse_csv(self._parse_conjunction)\n            each = self._match_text_seq(\"EACH\") and self._parse_conjunction()\n\n            return self.expression(exp.RangeN, this=this, expressions=expressions, each=each)\n\n    class Generator(generator.Generator):\n        JOIN_HINTS = False\n        TABLE_HINTS = False\n        QUERY_HINTS = False\n\n        TYPE_MAPPING = {\n            **generator.Generator.TYPE_MAPPING,\n            exp.DataType.Type.GEOMETRY: \"ST_GEOMETRY\",\n        }\n\n        PROPERTIES_LOCATION = {\n            **generator.Generator.PROPERTIES_LOCATION,\n            exp.OnCommitProperty: exp.Properties.Location.POST_INDEX,\n            exp.PartitionedByProperty: exp.Properties.Location.POST_EXPRESSION,\n            exp.StabilityProperty: exp.Properties.Location.POST_CREATE,\n        }\n\n        TRANSFORMS = {\n            **generator.Generator.TRANSFORMS,\n            exp.Max: max_or_greatest,\n            exp.Min: min_or_least,\n            exp.Select: transforms.preprocess([transforms.eliminate_distinct_on]),\n            exp.StrToDate: lambda self, e: f\"CAST({self.sql(e, 'this')} AS DATE FORMAT {self.format_time(e)})\",\n            exp.ToChar: lambda self, e: self.function_fallback_sql(e),\n            exp.Use: lambda self, e: f\"DATABASE {self.sql(e, 'this')}\",\n        }\n\n        def partitionedbyproperty_sql(self, expression: exp.PartitionedByProperty) -> str:\n            return f\"PARTITION BY {self.sql(expression, 'this')}\"\n\n        # FROM before SET in Teradata UPDATE syntax\n        # https://docs.teradata.com/r/Enterprise_IntelliFlex_VMware/Teradata-VantageTM-SQL-Data-Manipulation-Language-17.20/Statement-Syntax/UPDATE/UPDATE-Syntax-Basic-Form-FROM-Clause\n        def update_sql(self, expression: exp.Update) -> str:\n            this = self.sql(expression, \"this\")\n            from_sql = self.sql(expression, \"from\")\n            set_sql = self.expressions(expression, flat=True)\n            where_sql = self.sql(expression, \"where\")\n            sql = f\"UPDATE {this}{from_sql} SET {set_sql}{where_sql}\"\n            return self.prepend_ctes(expression, sql)\n\n        def mod_sql(self, expression: exp.Mod) -> str:\n            return self.binary(expression, \"MOD\")\n\n        def datatype_sql(self, expression: exp.DataType) -> str:\n            type_sql = super().datatype_sql(expression)\n            prefix_sql = expression.args.get(\"prefix\")\n            return f\"SYSUDTLIB.{type_sql}\" if prefix_sql else type_sql\n\n        def rangen_sql(self, expression: exp.RangeN) -> str:\n            this = self.sql(expression, \"this\")\n            expressions_sql = self.expressions(expression)\n            each_sql = self.sql(expression, \"each\")\n            each_sql = f\" EACH {each_sql}\" if each_sql else \"\"\n\n            return f\"RANGE_N({this} BETWEEN {expressions_sql}{each_sql})\"\n\n        def createable_sql(self, expression: exp.Create, locations: t.DefaultDict) -> str:\n            kind = self.sql(expression, \"kind\").upper()\n            if kind == \"TABLE\" and locations.get(exp.Properties.Location.POST_NAME):\n                this_name = self.sql(expression.this, \"this\")\n                this_properties = self.properties(\n                    exp.Properties(expressions=locations[exp.Properties.Location.POST_NAME]),\n                    wrapped=False,\n                    prefix=\",\",\n                )\n                this_schema = self.schema_columns_sql(expression.this)\n                return f\"{this_name}{this_properties}{self.sep()}{this_schema}\"\n\n            return super().createable_sql(expression, locations)\n", "path": "sqlglot/dialects/teradata.py"}]}