MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / subquery

Method subquery

lib/sqlalchemy/orm/query.py:609–652  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

607 return stmt
608
609 def subquery(
610 self,
611 name: Optional[str] = None,
612 with_labels: bool = False,
613 reduce_columns: bool = False,
614 ) -> Subquery:
615 """Return the full SELECT statement represented by
616 this :class:`_query.Query`, embedded within an
617 :class:`_expression.Alias`.
618
619 Eager JOIN generation within the query is disabled.
620
621 .. seealso::
622
623 :meth:`_sql.Select.subquery` - v2 comparable method.
624
625 :param name: string name to be assigned as the alias;
626 this is passed through to :meth:`_expression.FromClause.alias`.
627 If ``None``, a name will be deterministically generated
628 at compile time.
629
630 :param with_labels: if True, :meth:`.with_labels` will be called
631 on the :class:`_query.Query` first to apply table-qualified labels
632 to all columns.
633
634 :param reduce_columns: if True,
635 :meth:`_expression.Select.reduce_columns` will
636 be called on the resulting :func:`_expression.select` construct,
637 to remove same-named columns where one also refers to the other
638 via foreign key or WHERE clause equivalence.
639
640 """
641 q = self.enable_eagerloads(False)
642 if with_labels:
643 q = q.set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
644
645 stmt = q._get_select_statement_only()
646
647 if TYPE_CHECKING:
648 assert isinstance(stmt, Select)
649
650 if reduce_columns:
651 stmt = stmt.reduce_columns()
652 return stmt.subquery(name=name)
653
654 def cte(
655 self,

Callers 15

_constraint_queryMethod · 0.45
_index_queryMethod · 0.45
_enum_queryMethod · 0.45
_domain_queryMethod · 0.45
_has_table_queryMethod · 0.45
get_table_namesMethod · 0.45
_comment_queryMethod · 0.45
_legacy_from_selfMethod · 0.45
_set_opMethod · 0.45
test_subqueryMethod · 0.45

Calls 4

enable_eagerloadsMethod · 0.95
reduce_columnsMethod · 0.80
set_label_styleMethod · 0.45