Using Joins
============
-
We're halfway along to being able to construct any SELECT expression. The next
cornerstone of the SELECT is the JOIN expression. We've already been doing
joins in our examples, by just placing two tables in either the columns clause
If you don't know what that SQL means, don't worry ! The secret tribe of
Oracle DBAs don't want their black magic being found out ;).
+.. seealso::
+
+ :func:`.expression.join`
+
+ :func:`.expression.outerjoin`
+
+ :class:`.Join`
+
Everything Else
================
Throughout all these examples, SQLAlchemy is busy creating bind parameters
wherever literal expressions occur. You can also specify your own bind
-parameters with your own names, and use the same statement repeatedly. The
-database dialect converts to the appropriate named or positional style, as
-here where it converts to positional for SQLite:
+parameters with your own names, and use the same statement repeatedly.
+The :func:`.bindparam` construct is used to produce a bound parameter
+with a given name. While SQLAlchemy always refers to bound parameters by
+name on the API side, the
+database dialect converts to the appropriate named or positional style
+at execution time, as here where it converts to positional for SQLite:
.. sourcecode:: pycon+sql
('wendy',)
{stop}[(2, u'wendy', u'Wendy Williams')]
-Another important aspect of bind parameters is that they may be assigned a
+Another important aspect of :func:`.bindparam` is that it may be assigned a
type. The type of the bind parameter will determine its behavior within
expressions and also how the data bound to it is processed before being sent
off to the database:
{stop}[(2, u'wendy', u'Wendy Williams')]
-Bind parameters of the same name can also be used multiple times, where only a
+:func:`.bindparam` constructs of the same name can also be used multiple times, where only a
single named value is needed in the execute parameters:
.. sourcecode:: pycon+sql
('jack', 'jack')
{stop}[(1, u'jack', u'Jack Jones', 1, 1, u'jack@yahoo.com'), (1, u'jack', u'Jack Jones', 2, 1, u'jack@msn.com')]
+.. seealso::
+
+ :func:`.bindparam`
+
Functions
---------
>>> s.compile().params
{u'x_2': 5, u'y_2': 12, u'y_1': 45, u'x_1': 17}
+.. seealso::
+
+ :data:`.func`
Window Functions
-----------------
Any :class:`.FunctionElement`, including functions generated by
:data:`~.expression.func`, can be turned into a "window function", that is an
-OVER clause, using the :meth:`~.FunctionElement.over` method:
+OVER clause, using the :meth:`.FunctionElement.over` method:
.. sourcecode:: pycon+sql
SELECT users.id, row_number() OVER (ORDER BY users.name) AS anon_1
FROM users
+.. seealso::
+
+ :func:`.over`
+
+ :meth:`.FunctionElement.over`
+
Unions and Other Set Operations
-------------------------------
('%@yahoo.com', '%@msn.com', '%@msn.com')
{stop}[(1, 1, u'jack@yahoo.com')]
+.. seealso::
+
+ :func:`.union`
+
+ :func:`.union_all`
+
+ :func:`.intersect`
+
+ :func:`.intersect_all`
+
+ :func:`.except_`
+
+ :func:`.except_all`
+
.. _scalar_selects:
Scalar Selects
()
{stop}[(u'jack', 2), (u'wendy', 2)]
+.. seealso::
+
+ :meth:`.Select.as_scalar`
+
+ :meth:`.Select.label`
+
.. _correlated_subqueries:
Correlated Subqueries