summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/functions.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-08-26 15:15:45 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2015-08-26 15:15:55 -0400
commitcfae9c2eaf0020be8d8acbe104cb693e0fee0796 (patch)
tree37e608da4c00e645b188341ff0a43b4bae42096b /lib/sqlalchemy/sql/functions.py
parent7024745a142e261efb6d878389d01a06673b655c (diff)
downloadsqlalchemy-cfae9c2eaf0020be8d8acbe104cb693e0fee0796.tar.gz
- Added support for the SQL-standard function :class:`.array_agg`,
which automatically returns an :class:`.Array` of the correct type and supports index / slice operations. As arrays are only supported on Postgresql at the moment, only actually works on Postgresql. fixes #3132
Diffstat (limited to 'lib/sqlalchemy/sql/functions.py')
-rw-r--r--lib/sqlalchemy/sql/functions.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/functions.py b/lib/sqlalchemy/sql/functions.py
index 80ee31b0f..d536c3008 100644
--- a/lib/sqlalchemy/sql/functions.py
+++ b/lib/sqlalchemy/sql/functions.py
@@ -626,3 +626,25 @@ class sysdate(AnsiFunction):
class user(AnsiFunction):
type = sqltypes.String
+
+
+class array_agg(GenericFunction):
+ """support for the ARRAY_AGG function.
+
+ The ``func.array_agg(expr)`` construct returns an expression of
+ type :class:`.Array`.
+
+ e.g.
+
+ stmt = select([func.array_agg(table.c.values)[2:5]])
+
+ .. versionadded:: 1.1
+
+ """
+
+ def __init__(self, *args, **kwargs):
+ args = [_literal_as_binds(c) for c in args]
+ kwargs.setdefault('type_', sqltypes.Array(_type_from_args(args)))
+ kwargs['_parsed_args'] = args
+ GenericFunction.__init__(self, *args, **kwargs)
+