summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/__init__.py5
-rw-r--r--lib/sqlalchemy/dialects/postgresql/array.py4
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py5
-rw-r--r--lib/sqlalchemy/dialects/postgresql/ext.py14
-rw-r--r--lib/sqlalchemy/sql/functions.py11
5 files changed, 33 insertions, 6 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/__init__.py b/lib/sqlalchemy/dialects/postgresql/__init__.py
index 2dac6cecc..d67f2a07e 100644
--- a/lib/sqlalchemy/dialects/postgresql/__init__.py
+++ b/lib/sqlalchemy/dialects/postgresql/__init__.py
@@ -17,7 +17,7 @@ from .base import \
from .hstore import HSTORE, hstore
from .json import JSON, JSONB
from .array import array, ARRAY, Any, All
-from .ext import aggregate_order_by, ExcludeConstraint
+from .ext import aggregate_order_by, ExcludeConstraint, array_agg
from .ranges import INT4RANGE, INT8RANGE, NUMRANGE, DATERANGE, TSRANGE, \
TSTZRANGE
@@ -29,5 +29,6 @@ __all__ = (
'INTERVAL', 'ARRAY', 'ENUM', 'dialect', 'array', 'HSTORE',
'hstore', 'INT4RANGE', 'INT8RANGE', 'NUMRANGE', 'DATERANGE',
'TSRANGE', 'TSTZRANGE', 'json', 'JSON', 'JSONB', 'Any', 'All',
- 'DropEnumType', 'CreateEnumType', 'ExcludeConstraint', 'aggregate_order_by'
+ 'DropEnumType', 'CreateEnumType', 'ExcludeConstraint',
+ 'aggregate_order_by', 'array_agg'
)
diff --git a/lib/sqlalchemy/dialects/postgresql/array.py b/lib/sqlalchemy/dialects/postgresql/array.py
index 68c7b0bdb..ebdfe1695 100644
--- a/lib/sqlalchemy/dialects/postgresql/array.py
+++ b/lib/sqlalchemy/dialects/postgresql/array.py
@@ -22,7 +22,7 @@ def Any(other, arrexpr, operator=operators.eq):
.. seealso::
- :func:`.expression.any`
+ :func:`.expression.any_`
"""
@@ -36,7 +36,7 @@ def All(other, arrexpr, operator=operators.eq):
.. seealso::
- :func:`.expression.all`
+ :func:`.expression.all_`
"""
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py
index 4022db14b..ec12e1145 100644
--- a/lib/sqlalchemy/dialects/postgresql/base.py
+++ b/lib/sqlalchemy/dialects/postgresql/base.py
@@ -518,6 +518,11 @@ as well as array literals:
* :class:`.postgresql.array` - array literal
+* :func:`.postgresql.array_agg` - ARRAY_AGG SQL function
+
+* :class:`.postgresql.aggregate_order_by` - helper for PG's ORDER BY aggregate
+ function syntax.
+
JSON Types
----------
diff --git a/lib/sqlalchemy/dialects/postgresql/ext.py b/lib/sqlalchemy/dialects/postgresql/ext.py
index 8b08cc498..9b2e3fd73 100644
--- a/lib/sqlalchemy/dialects/postgresql/ext.py
+++ b/lib/sqlalchemy/dialects/postgresql/ext.py
@@ -7,7 +7,9 @@
from ...sql import expression
from ...sql import elements
+from ...sql import functions
from ...sql.schema import ColumnCollectionConstraint
+from .array import ARRAY
class aggregate_order_by(expression.ColumnElement):
@@ -152,3 +154,15 @@ static/sql-createtable.html#SQL-CREATETABLE-EXCLUDE
initially=self.initially)
c.dispatch._update(self.dispatch)
return c
+
+
+def array_agg(*arg, **kw):
+ """Postgresql-specific form of :class:`.array_agg`, ensures
+ return type is :class:`.postgresql.ARRAY` and not
+ the plain :class:`.types.Array`.
+
+ .. versionadded:: 1.1
+
+ """
+ kw['type_'] = ARRAY(functions._type_from_args(arg))
+ return functions.func.array_agg(*arg, **kw)
diff --git a/lib/sqlalchemy/sql/functions.py b/lib/sqlalchemy/sql/functions.py
index d5d0eb7f2..6cfbd12b3 100644
--- a/lib/sqlalchemy/sql/functions.py
+++ b/lib/sqlalchemy/sql/functions.py
@@ -661,17 +661,24 @@ class array_agg(GenericFunction):
The ``func.array_agg(expr)`` construct returns an expression of
type :class:`.Array`.
- e.g.
+ e.g.::
stmt = select([func.array_agg(table.c.values)[2:5]])
.. versionadded:: 1.1
+ .. seealso::
+
+ :func:`.postgresql.array_agg` - PostgreSQL-specific version that
+ returns :class:`.ARRAY`, which has PG-specific operators added.
+
"""
+ type = sqltypes.Array
+
def __init__(self, *args, **kwargs):
args = [_literal_as_binds(c) for c in args]
- kwargs.setdefault('type_', sqltypes.Array(_type_from_args(args)))
+ kwargs.setdefault('type_', self.type(_type_from_args(args)))
kwargs['_parsed_args'] = args
super(array_agg, self).__init__(*args, **kwargs)