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

Method select_from

lib/sqlalchemy/orm/query.py:2514–2560  ·  view source on GitHub ↗

r"""Set the FROM clause of this :class:`.Query` explicitly. :meth:`.Query.select_from` is often used in conjunction with :meth:`.Query.join` in order to control which entity is selected from on the "left" side of the join. The entity or selectable object here effect

(self, *from_obj: _FromClauseArgument)

Source from the content-addressed store, hash-verified

2512 @_generative
2513 @_assertions(_no_clauseelement_condition)
2514 def select_from(self, *from_obj: _FromClauseArgument) -> Self:
2515 r"""Set the FROM clause of this :class:`.Query` explicitly.
2516
2517 :meth:`.Query.select_from` is often used in conjunction with
2518 :meth:`.Query.join` in order to control which entity is selected
2519 from on the "left" side of the join.
2520
2521 The entity or selectable object here effectively replaces the
2522 "left edge" of any calls to :meth:`~.Query.join`, when no
2523 joinpoint is otherwise established - usually, the default "join
2524 point" is the leftmost entity in the :class:`~.Query` object's
2525 list of entities to be selected.
2526
2527 A typical example::
2528
2529 q = (
2530 session.query(Address)
2531 .select_from(User)
2532 .join(User.addresses)
2533 .filter(User.name == "ed")
2534 )
2535
2536 Which produces SQL equivalent to:
2537
2538 .. sourcecode:: sql
2539
2540 SELECT address.* FROM user
2541 JOIN address ON user.id=address.user_id
2542 WHERE user.name = :name_1
2543
2544 :param \*from_obj: collection of one or more entities to apply
2545 to the FROM clause. Entities can be mapped classes,
2546 :class:`.AliasedClass` objects, :class:`.Mapper` objects
2547 as well as core :class:`.FromClause` elements like subqueries.
2548
2549 .. seealso::
2550
2551 :meth:`~.Query.join`
2552
2553 :meth:`.Query.select_entity_from`
2554
2555 :meth:`_sql.Select.select_from` - v2 equivalent method.
2556
2557 """
2558
2559 self._set_select_from(from_obj, False)
2560 return self
2561
2562 @overload
2563 def __getitem__(self, item: slice) -> List[_T]: ...

Callers 15

get_view_definitionMethod · 0.45
_columns_queryMethod · 0.45
_constraint_queryMethod · 0.45
_foreing_key_queryMethod · 0.45
_index_queryMethod · 0.45
_comment_queryMethod · 0.45
_all_objects_queryMethod · 0.45
get_table_namesMethod · 0.45
_column_queryMethod · 0.45
_index_queryMethod · 0.45
_constraint_queryMethod · 0.45

Calls 1

_set_select_fromMethod · 0.95

Tested by 15

test_inner_join_fkMethod · 0.36
test_inner_join_trueMethod · 0.36
test_inner_join_falseMethod · 0.36
test_outer_join_falseMethod · 0.36
test_outer_join_fkMethod · 0.36
test_select_allMethod · 0.36
test_select_columnsMethod · 0.36
test_select_allMethod · 0.36
test_distinct_onMethod · 0.36
test_aliases_and_ssMethod · 0.36
test_in_27Method · 0.36