Return the full SELECT statement represented by this :class:`_query.Query`, embedded within an :class:`_expression.Alias`. Eager JOIN generation within the query is disabled. .. seealso:: :meth:`_sql.Select.subquery` - v2 comparable method. :pa
(
self,
name: Optional[str] = None,
with_labels: bool = False,
reduce_columns: bool = False,
)
| 627 | return stmt |
| 628 | |
| 629 | def subquery( |
| 630 | self, |
| 631 | name: Optional[str] = None, |
| 632 | with_labels: bool = False, |
| 633 | reduce_columns: bool = False, |
| 634 | ) -> Subquery: |
| 635 | """Return the full SELECT statement represented by |
| 636 | this :class:`_query.Query`, embedded within an |
| 637 | :class:`_expression.Alias`. |
| 638 | |
| 639 | Eager JOIN generation within the query is disabled. |
| 640 | |
| 641 | .. seealso:: |
| 642 | |
| 643 | :meth:`_sql.Select.subquery` - v2 comparable method. |
| 644 | |
| 645 | :param name: string name to be assigned as the alias; |
| 646 | this is passed through to :meth:`_expression.FromClause.alias`. |
| 647 | If ``None``, a name will be deterministically generated |
| 648 | at compile time. |
| 649 | |
| 650 | :param with_labels: if True, :meth:`.with_labels` will be called |
| 651 | on the :class:`_query.Query` first to apply table-qualified labels |
| 652 | to all columns. |
| 653 | |
| 654 | :param reduce_columns: if True, |
| 655 | :meth:`_expression.Select.reduce_columns` will |
| 656 | be called on the resulting :func:`_expression.select` construct, |
| 657 | to remove same-named columns where one also refers to the other |
| 658 | via foreign key or WHERE clause equivalence. |
| 659 | |
| 660 | """ |
| 661 | q = self.enable_eagerloads(False) |
| 662 | if with_labels: |
| 663 | q = q.set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL) |
| 664 | |
| 665 | stmt = q._get_select_statement_only() |
| 666 | |
| 667 | if TYPE_CHECKING: |
| 668 | assert isinstance(stmt, Select) |
| 669 | |
| 670 | if reduce_columns: |
| 671 | stmt = stmt.reduce_columns() |
| 672 | return stmt.subquery(name=name) |
| 673 | |
| 674 | def cte( |
| 675 | self, |