Skip to content

Commit

Permalink
Fix: dialect build
Browse files Browse the repository at this point in the history
  • Loading branch information
tobymao committed Jun 15, 2023
1 parent 9660c33 commit b86f7e8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions sqlglot/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3379,8 +3379,9 @@ def build(
from sqlglot import parse_one

if isinstance(dtype, str):
if dtype.upper() in cls.Type.__members__:
data_type_exp: t.Optional[Expression] = DataType(this=DataType.Type[dtype.upper()])
dtype = dtype.upper()
if not dialect and dtype in cls.Type.__members__:
data_type_exp: t.Optional[Expression] = DataType(this=DataType.Type[dtype])
else:
data_type_exp = parse_one(dtype, read=dialect, into=DataType)

Expand Down
1 change: 1 addition & 0 deletions tests/test_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ def test_data_type_builder(self):
self.assertEqual(exp.DataType.build("OBJECT").sql(), "OBJECT")
self.assertEqual(exp.DataType.build("NULL").sql(), "NULL")
self.assertEqual(exp.DataType.build("UNKNOWN").sql(), "UNKNOWN")
self.assertEqual(exp.DataType.build("TIMESTAMP", dialect="bigquery").sql(), "TIMESTAMPTZ")

def test_rename_table(self):
self.assertEqual(
Expand Down

0 comments on commit b86f7e8

Please sign in to comment.