Skip to content

Commit 09882e3

Browse files
committed
Fix(tsql): remove assert call from _build_formatted_time
1 parent 1df7f61 commit 09882e3

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

sqlglot/dialects/tsql.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,24 @@ def _build_formatted_time(
109109
exp_class: t.Type[E], full_format_mapping: t.Optional[bool] = None
110110
) -> t.Callable[[t.List], E]:
111111
def _builder(args: t.List) -> E:
112-
assert len(args) == 2
113-
114-
return exp_class(
115-
this=exp.cast(args[1], exp.DataType.Type.DATETIME2),
116-
format=exp.Literal.string(
112+
fmt = seq_get(args, 0)
113+
if isinstance(fmt, exp.Expression):
114+
fmt = exp.Literal.string(
117115
format_time(
118-
args[0].name.lower(),
116+
fmt.name.lower(),
119117
(
120118
{**TSQL.TIME_MAPPING, **FULL_FORMAT_TIME_MAPPING}
121119
if full_format_mapping
122120
else TSQL.TIME_MAPPING
123121
),
124122
)
125-
),
126-
)
123+
)
124+
125+
this = seq_get(args, 1)
126+
if isinstance(this, exp.Expression):
127+
this = exp.cast(this, exp.DataType.Type.DATETIME2)
128+
129+
return exp_class(this=this, format=fmt)
127130

128131
return _builder
129132

0 commit comments

Comments
 (0)