]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add order by to union example
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 23 Apr 2021 23:15:48 +0000 (19:15 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 23 Apr 2021 23:15:48 +0000 (19:15 -0400)
the query in the second union example needs order by to
produce determinstic results on all plaforms including
OSX, arm

Change-Id: I88fcc391561db8567c389ed9e904e5de29c1c2ad

doc/build/tutorial/data_select.rst

index 39ea937aa3209f05720a88941bc3a14fa7358fbd..73261500ea62705c6af7f5f947f3d3db7a067cb8 100644 (file)
@@ -1077,7 +1077,11 @@ it provides a :meth:`_sql.SelectBase.subquery` method which will produce a
 collection that may be referred towards in an enclosing :func:`_sql.select`::
 
     >>> u_subq = u.subquery()
-    >>> stmt = select(u_subq.c.name, address_table.c.email_address).join_from(address_table, u_subq)
+    >>> stmt = (
+    ...     select(u_subq.c.name, address_table.c.email_address).
+    ...     join_from(address_table, u_subq).
+    ...     order_by(u_subq.c.name, address_table.c.email_address)
+    ... )
     >>> with engine.connect() as conn:
     ...     result = conn.execute(stmt)
     ...     print(result.all())
@@ -1092,8 +1096,9 @@ collection that may be referred towards in an enclosing :func:`_sql.select`::
       FROM user_account
       WHERE user_account.name = ?)
     AS anon_1 ON anon_1.id = address.user_id
+    ORDER BY anon_1.name, address.email_address
     [generated in ...] ('sandy', 'spongebob')
-    {stop}[('spongebob', 'spongebob@sqlalchemy.org'), ('sandy', 'sandy@sqlalchemy.org'), ('sandy', 'sandy@squirrelpower.org')]
+    {stop}[('sandy', 'sandy@sqlalchemy.org'), ('sandy', 'sandy@squirrelpower.org'), ('spongebob', 'spongebob@sqlalchemy.org')]
     {opensql}ROLLBACK{stop}