@@ -402,9 +402,10 @@ def _unix_to_time_sql(self: DuckDB.Generator, expression: exp.UnixToTime) -> str
402402
403403 if scale in (None , exp .UnixToTime .SECONDS ):
404404 # TO_TIMESTAMP returns TIMESTAMPTZ. For NTZ, use AT TIME ZONE 'UTC' to get UTC as naive.
405+ to_timestamp : exp .Expression = exp .Anonymous (this = "TO_TIMESTAMP" , expressions = [timestamp ])
405406 if is_ntz :
406- return f"TO_TIMESTAMP( { self . sql ( timestamp ) } ) AT TIME ZONE ' UTC'"
407- return self .func ( "TO_TIMESTAMP" , timestamp )
407+ to_timestamp = exp . AtTimeZone ( this = to_timestamp , zone = exp . Literal . string ( " UTC" ))
408+ return self .sql ( to_timestamp )
408409 if scale == exp .UnixToTime .MILLIS :
409410 # EPOCH_MS already returns TIMESTAMP (naive, UTC)
410411 return self .func ("EPOCH_MS" , timestamp )
@@ -413,10 +414,13 @@ def _unix_to_time_sql(self: DuckDB.Generator, expression: exp.UnixToTime) -> str
413414 return self .func ("MAKE_TIMESTAMP" , timestamp )
414415
415416 # Other scales: divide and use TO_TIMESTAMP
416- div_expr = exp .Div (this = timestamp , expression = exp .func ("POW" , 10 , scale ))
417+ timestamp = exp .Div (this = timestamp , expression = exp .func ("POW" , 10 , scale ))
418+ to_timestamp = exp .Anonymous (this = "TO_TIMESTAMP" , expressions = [timestamp ])
419+
417420 if is_ntz :
418- return f"TO_TIMESTAMP({ self .sql (div_expr )} ) AT TIME ZONE 'UTC'"
419- return self .func ("TO_TIMESTAMP" , div_expr )
421+ to_timestamp = exp .AtTimeZone (this = to_timestamp , zone = exp .Literal .string ("UTC" ))
422+
423+ return self .sql (to_timestamp )
420424
421425
422426WRAPPED_JSON_EXTRACT_EXPRESSIONS = (exp .Binary , exp .Bracket , exp .In )
0 commit comments