]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
A few doc tweaks for alias / order_by / group_by
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 1 Jul 2019 17:09:44 +0000 (13:09 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 1 Jul 2019 17:10:12 +0000 (13:10 -0400)
Change-Id: Ib3b46b45735529d68ebfb3784de4de5d2d0f4abc
(cherry picked from commit 3b60ccaed4844d25617221c853b3e46a78fd7974)

doc/build/core/tutorial.rst
lib/sqlalchemy/sql/selectable.py

index 04c74a63620e8cd6fe3d5ae0d863b31b0b9e2f36..a829c99c563f30a46845a5b70b076d29f112cbac 100644 (file)
@@ -1083,6 +1083,7 @@ by a column name that appears more than once:
 
 
 
+.. _core_tutorial_aliases:
 
 Using Aliases
 =============
@@ -1799,6 +1800,8 @@ specified to :meth:`.Select.correlate_except`.
     :meth:`.Select.lateral`
 
 
+.. _core_tutorial_ordering:
+
 Ordering, Grouping, Limiting, Offset...ing...
 ---------------------------------------------
 
index 1167b15258ec92510dafea1e8686fd9cf00b525a..03ca9a42dba2cd65b2ff2c834a33206af9c69459 100644 (file)
@@ -419,12 +419,18 @@ class FromClause(Selectable):
     def alias(self, name=None, flat=False):
         """return an alias of this :class:`.FromClause`.
 
-        This is shorthand for calling::
+        E.g.::
+
+            a2 = some_table.alias('a2')
 
-            from sqlalchemy import alias
-            a = alias(self, name=name)
+        The above code creates an :class:`.Alias` object which can be used
+        as a FROM clause in any SELECT statement.
 
-        See :func:`~.expression.alias` for details.
+        .. seealso::
+
+            :ref:`core_tutorial_aliases`
+
+            :func:`~.expression.alias`
 
         """
 
@@ -1166,6 +1172,8 @@ class Join(FromClause):
 
         .. seealso::
 
+            :ref:`core_tutorial_aliases`
+
             :func:`~.expression.alias`
 
         """
@@ -1251,7 +1259,10 @@ class Alias(FromClause):
 
         Similar functionality is available via the
         :meth:`~.FromClause.alias` method
-        available on all :class:`.FromClause` subclasses.
+        available on all :class:`.FromClause` subclasses.   In terms of a
+        SELECT object as generated from the :func:`.select` function, the
+        :meth:`.SelectBase.alias` method returns an :class:`.Alias` or
+        similar object which represents a named, parenthesized subquery.
 
         When an :class:`.Alias` is created from a :class:`.Table` object,
         this has the effect of the table being rendered
@@ -1547,6 +1558,18 @@ class CTE(Generative, HasSuffixes, Alias):
                 col._make_proxy(self)
 
     def alias(self, name=None, flat=False):
+        """Return an :class:`.Alias` of this :class:`.CTE`.
+
+        This method is a CTE-specific specialization of the
+        :class:`.FromClause.alias` method.
+
+        .. seealso::
+
+            :ref:`core_tutorial_aliases`
+
+            :func:`~.expression.alias`
+
+        """
         return CTE._construct(
             self.original,
             name=name,
@@ -2331,11 +2354,19 @@ class GenerativeSelect(SelectBase):
 
     @_generative
     def order_by(self, *clauses):
-        """return a new selectable with the given list of ORDER BY
+        r"""return a new selectable with the given list of ORDER BY
         criterion applied.
 
-        The criterion will be appended to any pre-existing ORDER BY
-        criterion.
+        e.g.::
+
+            stmt = select([table]).order_by(table.c.id, table.c.name)
+
+        :param \*order_by: a series of :class:`.ColumnElement` constructs
+         which will be used to generate an ORDER BY clause.
+
+        .. seealso::
+
+            :ref:`core_tutorial_ordering`
 
         """
 
@@ -2343,11 +2374,20 @@ class GenerativeSelect(SelectBase):
 
     @_generative
     def group_by(self, *clauses):
-        """return a new selectable with the given list of GROUP BY
+        r"""return a new selectable with the given list of GROUP BY
         criterion applied.
 
-        The criterion will be appended to any pre-existing GROUP BY
-        criterion.
+        e.g.::
+
+            stmt = select([table.c.name, func.max(table.c.stat)]).\
+            group_by(table.c.name)
+
+        :param \*group_by: a series of :class:`.ColumnElement` constructs
+         which will be used to generate an GROUP BY clause.
+
+        .. seealso::
+
+            :ref:`core_tutorial_ordering`
 
         """
 
@@ -2362,6 +2402,10 @@ class GenerativeSelect(SelectBase):
         :meth:`~.GenerativeSelect.order_by` method is preferred, as it
         provides standard :term:`method chaining`.
 
+        .. seealso::
+
+            :meth:`.GenerativeSelect.order_by`
+
         """
         if len(clauses) == 1 and clauses[0] is None:
             self._order_by_clause = ClauseList()
@@ -2382,6 +2426,10 @@ class GenerativeSelect(SelectBase):
         :meth:`~.GenerativeSelect.group_by` method is preferred, as it
         provides standard :term:`method chaining`.
 
+        .. seealso::
+
+            :meth:`.GenerativeSelect.group_by`
+
         """
         if len(clauses) == 1 and clauses[0] is None:
             self._group_by_clause = ClauseList()