@@ -419,6 +419,20 @@ def _parse_limit(
419419 return macro
420420
421421
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+
422436def _parse_macro_or_clause (self : Parser , parser : t .Callable ) -> t .Optional [exp .Expression ]:
423437 return _parse_macro (self ) if self ._match (TokenType .PARAMETER ) else parser ()
424438
@@ -1063,6 +1077,7 @@ def extend_sqlglot() -> None:
10631077 _override (Parser , _parse_with )
10641078 _override (Parser , _parse_having )
10651079 _override (Parser , _parse_limit )
1080+ _override (Parser , _parse_value )
10661081 _override (Parser , _parse_lambda )
10671082 _override (Parser , _parse_types )
10681083 _override (Parser , _parse_if )
0 commit comments