- changed milestone to 0.8.xx
- marked as enhancement
Postgresql array.contains doesn't accept set objects
(original reporter: taha_jahangir) When calling a query with .filter(my_col.contains({1, 2, 3})
, (in sqlalchemy 0.8) The following error raises:
sqlalchemy.exc.StatementError: 'set' object does not support indexing (original cause: TypeError: 'set' object does not support indexing)
with traceback:
File "build/bdist.freebsd-9.0-RELEASE-amd64/egg/sqlalchemy/orm/query.py", line 2049, in __getitem__
return list(res)
File "build/bdist.freebsd-9.0-RELEASE-amd64/egg/sqlalchemy/orm/query.py", line 2253, in __iter__
return self._execute_and_instances(context)
File "build/bdist.freebsd-9.0-RELEASE-amd64/egg/sqlalchemy/orm/query.py", line 2268, in _execute_and_instances
result = conn.execute(querycontext.statement, self._params)
File "build/bdist.freebsd-9.0-RELEASE-amd64/egg/sqlalchemy/engine/base.py", line 664, in execute
params)
File "build/bdist.freebsd-9.0-RELEASE-amd64/egg/sqlalchemy/engine/base.py", line 764, in _execute_clauseelement
compiled_sql, distilled_params
File "build/bdist.freebsd-9.0-RELEASE-amd64/egg/sqlalchemy/engine/base.py", line 831, in _execute_context
None, None)
File "build/bdist.freebsd-9.0-RELEASE-amd64/egg/sqlalchemy/engine/base.py", line 1036, in _handle_dbapi_exception
from e
This code was correct and running with sqlalchemy 0.7.
This is also true for generator objects, like {{{ .filter(my_col.contains(obj.id for obj in objects)) }}}
Comments (6)
-
repo owner -
Account Deleted (original author: taha_jahangir) The code was
column.op('@>')(set_or_list_object)
in sqlalchemy 0.7 -
repo owner OK, sets/generators/whatever are supported, but you must specify a dimension for the ARRAY:
Table('mytable', metadata, Column('x', ARRAY(Integer, dimensions=1))
otherwise we have to guess how many dimensions are being sent, which requires looking into
arr[0](0)
which only works for list/tuple. You want to have a "dimension" specified always. The error message is now informative:"Cannot auto-coerce ARRAY value of type " "%s unless dimensions are specified " "for ARRAY type" % type(arr))
-
repo owner scratch that, I just coerce to a list() in all cases, so now it just works (at the expense of even more performance if you don't specify a dimension, so specify a dimension!)
-
repo owner I just broke empty arrays on that, fixed in 63c211f42730011760aa8e3f88b2171b23bc0a60.
-
repo owner - removed milestone
Removing milestone: 0.8.xx (automated comment)
- Log in to comment
Replying to taha_jahangir:
I don't see how that's possible - we had no support for "contains()" for ARRAY types in 0.7. Here's a test, feel free to show me your actual code (which is always very helpful, as I don't have to guess what you were doing, as I am having to do here...)
as expected, "contains" in 0.7 was only for string types and we get this:
totally reasonable feature add of course but I'm not able to produce evidence that this is a regression without further information.