@@ -419,6 +419,20 @@ def _parse_limit(
419
419
return macro
420
420
421
421
422
+ def _parse_value (self : Parser , values : bool = True ) -> t .Optional [exp .Expression ]:
423
+ wrapped = self ._match (TokenType .L_PAREN , advance = False )
424
+
425
+ # The base _parse_value method always constructs a Tuple instance. This is problematic when
426
+ # generating values with a macro function, because it's impossible to tell whether the user's
427
+ # intention was to construct a row or a column with the VALUES expression. To avoid this, we
428
+ # amend the AST such that the Tuple is replaced by the macro function call itself.
429
+ expr = self .__parse_value () # type: ignore
430
+ if expr and not wrapped and isinstance (seq_get (expr .expressions , 0 ), MacroFunc ):
431
+ return expr .expressions [0 ]
432
+
433
+ return expr
434
+
435
+
422
436
def _parse_macro_or_clause (self : Parser , parser : t .Callable ) -> t .Optional [exp .Expression ]:
423
437
return _parse_macro (self ) if self ._match (TokenType .PARAMETER ) else parser ()
424
438
@@ -1063,6 +1077,7 @@ def extend_sqlglot() -> None:
1063
1077
_override (Parser , _parse_with )
1064
1078
_override (Parser , _parse_having )
1065
1079
_override (Parser , _parse_limit )
1080
+ _override (Parser , _parse_value )
1066
1081
_override (Parser , _parse_lambda )
1067
1082
_override (Parser , _parse_types )
1068
1083
_override (Parser , _parse_if )
0 commit comments