Produce a :class:`_expression.Join` object, given two :class:`_expression.FromClause` expressions. E.g.:: j = join( user_table, address_table, user_table.c.id == address_table.c.user_id ) stmt = select(user_table).select_from(j) would emit SQL a
(
left: _FromClauseArgument,
right: _FromClauseArgument,
onclause: Optional[_OnClauseArgument] = None,
isouter: bool = False,
full: bool = False,
)
| 273 | |
| 274 | |
| 275 | def join( |
| 276 | left: _FromClauseArgument, |
| 277 | right: _FromClauseArgument, |
| 278 | onclause: Optional[_OnClauseArgument] = None, |
| 279 | isouter: bool = False, |
| 280 | full: bool = False, |
| 281 | ) -> Join: |
| 282 | """Produce a :class:`_expression.Join` object, given two |
| 283 | :class:`_expression.FromClause` |
| 284 | expressions. |
| 285 | |
| 286 | E.g.:: |
| 287 | |
| 288 | j = join( |
| 289 | user_table, address_table, user_table.c.id == address_table.c.user_id |
| 290 | ) |
| 291 | stmt = select(user_table).select_from(j) |
| 292 | |
| 293 | would emit SQL along the lines of: |
| 294 | |
| 295 | .. sourcecode:: sql |
| 296 | |
| 297 | SELECT user.id, user.name FROM user |
| 298 | JOIN address ON user.id = address.user_id |
| 299 | |
| 300 | Similar functionality is available given any |
| 301 | :class:`_expression.FromClause` object (e.g. such as a |
| 302 | :class:`_schema.Table`) using |
| 303 | the :meth:`_expression.FromClause.join` method. |
| 304 | |
| 305 | :param left: The left side of the join. |
| 306 | |
| 307 | :param right: the right side of the join; this is any |
| 308 | :class:`_expression.FromClause` object such as a |
| 309 | :class:`_schema.Table` object, and |
| 310 | may also be a selectable-compatible object such as an ORM-mapped |
| 311 | class. |
| 312 | |
| 313 | :param onclause: a SQL expression representing the ON clause of the |
| 314 | join. If left at ``None``, :meth:`_expression.FromClause.join` |
| 315 | will attempt to |
| 316 | join the two tables based on a foreign key relationship. |
| 317 | |
| 318 | :param isouter: if True, render a LEFT OUTER JOIN, instead of JOIN. |
| 319 | |
| 320 | :param full: if True, render a FULL OUTER JOIN, instead of JOIN. |
| 321 | |
| 322 | .. seealso:: |
| 323 | |
| 324 | :meth:`_expression.FromClause.join` - method form, |
| 325 | based on a given left side. |
| 326 | |
| 327 | :class:`_expression.Join` - the type of object produced. |
| 328 | |
| 329 | """ # noqa: E501 |
| 330 | |
| 331 | return Join(left, right, onclause, isouter, full) |
| 332 |