MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / select_from

Method select_from

lib/sqlalchemy/orm/query.py:2544–2590  ·  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

2542 @_generative
2543 @_assertions(_no_clauseelement_condition)
2544 def select_from(self, *from_obj: _FromClauseArgument) -> Self:
2545 r"""Set the FROM clause of this :class:`.Query` explicitly.
2546
2547 :meth:`.Query.select_from` is often used in conjunction with
2548 :meth:`.Query.join` in order to control which entity is selected
2549 from on the "left" side of the join.
2550
2551 The entity or selectable object here effectively replaces the
2552 "left edge" of any calls to :meth:`~.Query.join`, when no
2553 joinpoint is otherwise established - usually, the default "join
2554 point" is the leftmost entity in the :class:`~.Query` object's
2555 list of entities to be selected.
2556
2557 A typical example::
2558
2559 q = (
2560 session.query(Address)
2561 .select_from(User)
2562 .join(User.addresses)
2563 .filter(User.name == "ed")
2564 )
2565
2566 Which produces SQL equivalent to:
2567
2568 .. sourcecode:: sql
2569
2570 SELECT address.* FROM user
2571 JOIN address ON user.id=address.user_id
2572 WHERE user.name = :name_1
2573
2574 :param \*from_obj: collection of one or more entities to apply
2575 to the FROM clause. Entities can be mapped classes,
2576 :class:`.AliasedClass` objects, :class:`.Mapper` objects
2577 as well as core :class:`.FromClause` elements like subqueries.
2578
2579 .. seealso::
2580
2581 :meth:`~.Query.join`
2582
2583 :meth:`.Query.select_entity_from`
2584
2585 :meth:`_sql.Select.select_from` - v2 equivalent method.
2586
2587 """
2588
2589 self._set_select_from(from_obj, False)
2590 return self
2591
2592 @overload
2593 def __getitem__(self, item: slice) -> List[_T]: ...

Callers 15

get_view_definitionMethod · 0.45
_table_options_queryMethod · 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

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_cols_driver_colsMethod · 0.36
test_aliases_and_ssMethod · 0.36