summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql/base.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-04-22 16:57:15 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-04-22 16:57:15 -0400
commit422f4718715ad89346f42caf03bdd2ed745e5a23 (patch)
tree8f6f5737bfdf953ac5aa067b2978e08c29e20c48 /lib/sqlalchemy/dialects/postgresql/base.py
parente79fd50e586a4dcdefcd1181d726f47a713d02d3 (diff)
downloadsqlalchemy-422f4718715ad89346f42caf03bdd2ed745e5a23.tar.gz
The operators for the Postgresql ARRAY type supports
input types of sets, generators, etc. but only when a dimension is specified for the ARRAY; otherwise, the dialect needs to peek inside of "arr[0]" to guess how many dimensions are in use. If this occurs with a non list/tuple type, the error message is now informative and directs to specify a dimension for the ARRAY. [ticket:2681]
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/base.py')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py
index c59caff8d..f3a88ff70 100644
--- a/lib/sqlalchemy/dialects/postgresql/base.py
+++ b/lib/sqlalchemy/dialects/postgresql/base.py
@@ -669,10 +669,22 @@ class ARRAY(sqltypes.Concatenable, sqltypes.TypeEngine):
def compare_values(self, x, y):
return x == y
+ def _test_array_of_scalars(self, arr):
+ if not arr:
+ return True
+ else:
+ try:
+ return not isinstance(arr[0], (list, tuple))
+ except TypeError:
+ raise TypeError(
+ "Cannot auto-coerce ARRAY value of type "
+ "%s unless dimensions are specified "
+ "for ARRAY type" % type(arr))
+
def _proc_array(self, arr, itemproc, dim, collection):
if dim == 1 or (
dim is None and
- (not arr or not isinstance(arr[0], (list, tuple)))
+ self._test_array_of_scalars(arr)
):
if itemproc:
return collection(itemproc(x) for x in arr)