diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-08-27 11:21:25 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-08-27 11:22:05 -0400 |
| commit | 410be197ef5df234205b35f0d318b106a34e7f92 (patch) | |
| tree | 369b0217b874a68190833f5884b8a37f3043d159 /lib/sqlalchemy/dialects | |
| parent | e2209f7534255855f33a2afedac913fbefe37484 (diff) | |
| download | sqlalchemy-410be197ef5df234205b35f0d318b106a34e7f92.tar.gz | |
- add a postgresql-specific form of array_agg() that injects the
ARRAY type, references #3132
Diffstat (limited to 'lib/sqlalchemy/dialects')
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/__init__.py | 5 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/array.py | 4 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 5 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/ext.py | 14 |
4 files changed, 24 insertions, 4 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) |
