summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2017-10-06 11:14:29 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2017-10-06 11:29:09 -0400
commit4bb8397ae3a9d65bd18eb1d7c951bf5121ea280a (patch)
tree99ed437324d1ceaf1b6022216862c3eac5d15884 /test/sql
parent2c280791886756422a8103769cf131b0fe292ffe (diff)
downloadsqlalchemy-4bb8397ae3a9d65bd18eb1d7c951bf5121ea280a.tar.gz
Fix array_agg to accommodate ARRAY arguments
Fixed bug in :func:`.array_agg` function where passing an argument that is already of type :class:`.ARRAY`, such as a Postgresql :obj:`.postgresql.array` construct, would produce a ``ValueError``, due to the function attempting to nest the arrays. Change-Id: Ibe5f6275d90e4868e6ef8a733de05acd44c05d78 Fixes: #4107
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_functions.py38
1 files changed, 37 insertions, 1 deletions
diff --git a/test/sql/test_functions.py b/test/sql/test_functions.py
index d244e9671..cbc02f4b8 100644
--- a/test/sql/test_functions.py
+++ b/test/sql/test_functions.py
@@ -590,13 +590,49 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
)
-class ReturnTypeTest(fixtures.TestBase):
+class ReturnTypeTest(AssertsCompiledSQL, fixtures.TestBase):
def test_array_agg(self):
expr = func.array_agg(column('data', Integer))
is_(expr.type._type_affinity, ARRAY)
is_(expr.type.item_type._type_affinity, Integer)
+ def test_array_agg_array_datatype(self):
+ expr = func.array_agg(column('data', ARRAY(Integer)))
+ is_(expr.type._type_affinity, ARRAY)
+ is_(expr.type.item_type._type_affinity, Integer)
+
+ def test_array_agg_array_literal_implicit_type(self):
+ from sqlalchemy.dialects.postgresql import array, ARRAY as PG_ARRAY
+ expr = array([column('data', Integer), column('d2', Integer)])
+
+ assert isinstance(expr.type, PG_ARRAY)
+
+ agg_expr = func.array_agg(expr)
+ assert isinstance(agg_expr.type, PG_ARRAY)
+ is_(agg_expr.type._type_affinity, ARRAY)
+ is_(agg_expr.type.item_type._type_affinity, Integer)
+
+ self.assert_compile(
+ agg_expr,
+ "array_agg(ARRAY[data, d2])",
+ dialect="postgresql"
+ )
+
+ def test_array_agg_array_literal_explicit_type(self):
+ from sqlalchemy.dialects.postgresql import array
+ expr = array([column('data', Integer), column('d2', Integer)])
+
+ agg_expr = func.array_agg(expr, type_=ARRAY(Integer))
+ is_(agg_expr.type._type_affinity, ARRAY)
+ is_(agg_expr.type.item_type._type_affinity, Integer)
+
+ self.assert_compile(
+ agg_expr,
+ "array_agg(ARRAY[data, d2])",
+ dialect="postgresql"
+ )
+
def test_mode(self):
expr = func.mode(0.5).within_group(
column('data', Integer).desc())