summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/functions.py
diff options
context:
space:
mode:
authorSpitcyn <a.ch.clr@gmail.com>2017-09-12 10:21:57 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2017-09-13 15:18:37 -0400
commit509d19e6fd38b8e9fec1c588ec958ad1246414a1 (patch)
tree8a823c6270c5e4b374b54fb87b013846bff7ada3 /lib/sqlalchemy/sql/functions.py
parent31f80b9eaeb3c3435b7f6679b41e434478b1d11c (diff)
downloadsqlalchemy-509d19e6fd38b8e9fec1c588ec958ad1246414a1.tar.gz
Implement placeholders for CUBE, ROLLUP, GROUPING SETSreview/mike_bayer/pr_github_383
Fixes: #3429 Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com> Change-Id: I870ee7dc801d553c5309c291402ec468b671e9a9 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/383
Diffstat (limited to 'lib/sqlalchemy/sql/functions.py')
-rw-r--r--lib/sqlalchemy/sql/functions.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/functions.py b/lib/sqlalchemy/sql/functions.py
index 08f1d32a5..9a9396fec 100644
--- a/lib/sqlalchemy/sql/functions.py
+++ b/lib/sqlalchemy/sql/functions.py
@@ -811,3 +811,65 @@ class cume_dist(GenericFunction):
"""
type = sqltypes.Numeric()
+
+
+class cube(GenericFunction):
+ r"""Implement the ``CUBE`` grouping operation.
+
+ This function is used as part of the GROUP BY of a statement,
+ e.g. :meth:`.Select.group_by`::
+
+ stmt = select(
+ [func.sum(table.c.value), table.c.col_1, table.c.col_2]
+ ).group_by(func.cube(table.c.col_1, table.c.col_2))
+
+ .. versionadded:: 1.2
+
+ """
+
+
+class rollup(GenericFunction):
+ r"""Implement the ``ROLLUP`` grouping operation.
+
+ This function is used as part of the GROUP BY of a statement,
+ e.g. :meth:`.Select.group_by`::
+
+ stmt = select(
+ [func.sum(table.c.value), table.c.col_1, table.c.col_2]
+ ).group_by(func.rollup(table.c.col_1, table.c.col_2))
+
+ .. versionadded:: 1.2
+
+ """
+
+
+class grouping_sets(GenericFunction):
+ r"""Implement the ``GROUPING SETS`` grouping operation.
+
+ This function is used as part of the GROUP BY of a statement,
+ e.g. :meth:`.Select.group_by`::
+
+ stmt = select(
+ [func.sum(table.c.value), table.c.col_1, table.c.col_2]
+ ).group_by(func.grouping_sets(table.c.col_1, table.c.col_2))
+
+ In order to group by multiple sets, use the :func:`.tuple_` construct::
+
+ from sqlalchemy import tuple_
+
+ stmt = select(
+ [
+ func.sum(table.c.value),
+ table.c.col_1, table.c.col_2,
+ table.c.col_3]
+ ).group_by(
+ func.grouping_sets(
+ tuple_(table.c.col_1, table.c.col_2),
+ tuple_(table.c.value, table.c.col_3),
+ )
+ )
+
+
+ .. versionadded:: 1.2
+
+ """