@@ -1673,8 +1673,10 @@ def load_sql_based_model(
16731673 if query_or_seed_insert is not None and (
16741674 isinstance (query_or_seed_insert , (exp .Query , d .JinjaQuery ))
16751675 or (
1676+ # Macro functions are allowed in place of model queries only when there are no
1677+ # other statements in the model definition, otherwise they would be ambiguous
16761678 isinstance (query_or_seed_insert , d .MacroFunc )
1677- and query_or_seed_insert .this .name .lower () == "union"
1679+ and ( query_or_seed_insert .this .name .lower () == "union" or len ( expressions ) == 2 )
16781680 )
16791681 ):
16801682 return create_sql_model (
@@ -1745,9 +1747,6 @@ def create_sql_model(
17451747 used_variables: The set of variable names used by this model.
17461748 """
17471749 if not isinstance (query , (exp .Query , d .JinjaQuery , d .MacroFunc )):
1748- # Users are not expected to pass in a single MacroFunc instance for a model's query;
1749- # this is an implementation detail which allows us to create python models that return
1750- # SQL, either in the form of SQLGlot expressions or just plain strings.
17511750 raise_config_error (
17521751 "A query is required and must be a SELECT statement, a UNION statement, or a JINJA_QUERY block" ,
17531752 path ,
@@ -2081,7 +2080,10 @@ def _split_sql_model_statements(
20812080 if (
20822081 isinstance (expr , (exp .Query , d .JinjaQuery ))
20832082 or expr == INSERT_SEED_MACRO_CALL
2084- or (isinstance (expr , d .MacroFunc ) and expr .this .name .lower () == "union" )
2083+ or (
2084+ isinstance (expr , d .MacroFunc )
2085+ and (expr .this .name .lower () == "union" or length == 1 )
2086+ )
20852087 ):
20862088 query_positions .append ((expr , idx ))
20872089 sql_statements .append (expr )
0 commit comments