# sqlglot.optimizer.expand_multi_table_selects API documentation

Edit on GitHub

# sqlglot.optimizer.expand_multi_table_selects

View Source

     1from sqlglot import exp
     2
     3
     4def expand_multi_table_selects(expression):
     5    """
     6    Replace multiple FROM expressions with JOINs.
     7
     8    Example:
     9        >>> from sqlglot import parse_one
    10        >>> expand_multi_table_selects(parse_one("SELECT * FROM x, y")).sql()
    11        'SELECT * FROM x CROSS JOIN y'
    12    """
    13    for from_ in expression.find_all(exp.From):
    14        parent = from_.parent
    15
    16        for query in from_.expressions[1:]:
    17            parent.join(
    18                query,
    19                join_type="CROSS",
    20                copy=False,
    21            )
    22            from_.expressions.remove(query)
    23
    24    return expression

def expand_multi_table_selects(expression): View Source

     5def expand_multi_table_selects(expression):
     6    """
     7    Replace multiple FROM expressions with JOINs.
     8
     9    Example:
    10        >>> from sqlglot import parse_one
    11        >>> expand_multi_table_selects(parse_one("SELECT * FROM x, y")).sql()
    12        'SELECT * FROM x CROSS JOIN y'
    13    """
    14    for from_ in expression.find_all(exp.From):
    15        parent = from_.parent
    16
    17        for query in from_.expressions[1:]:
    18            parent.join(
    19                query,
    20                join_type="CROSS",
    21                copy=False,
    22            )
    23            from_.expressions.remove(query)
    24
    25    return expression

Replace multiple FROM expressions with JOINs.

###### Example:

>     >>> from sqlglot import parse_one
>     >>> expand_multi_table_selects(parse_one("SELECT * FROM x, y")).sql()
>     'SELECT * FROM x CROSS JOIN y'