I was trying to use the Postrges array_agg() aggregate function against a column on a related table. In this case I wanted a list of timestamps from a related table, but I get an error that the list type is unhashable. The SQL that SA generates is as expected, and if I replace func.array_agg with something that
returns a hashable value like func.count() then it works as expected.

Is this a requirement that entities must be hashable? If so can I write a TypeDecorator that implements __hash__?

My code looks something like this:
qry=session.query(Task, func.array_agg(TaskHistory.updated))
qry=qry.join(Task.History)
qry=qry.filter(Task.priority<5).filter(Task.state!='Approved')
qry=qry.group_by(Task).order_by(Task.asset,Task.name)
results=qry.all()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/users/dgardner/src/pcs/asset/farm/<ipython console> in <module>()

/usr/lib/pymodules/python2.6/sqlalchemy/orm/query.pyc in all(self)
  1265
  1266         """
-> 1267         return list(self)
  1268
  1269     @_generative(_no_clauseelement_condition)

/usr/lib/pymodules/python2.6/sqlalchemy/orm/query.pyc in instances(self, cursor, _Query__context)
  1426
  1427             if filter:
-> 1428                 rows = filter(rows)
  1429
1430 if context.refresh_state and self._only_load_props and context.refresh_state in context.progress:

/usr/lib/pymodules/python2.6/sqlalchemy/util.pyc in unique_list(seq, compare_with)
  1087 def unique_list(seq, compare_with=set):
  1088     seen = compare_with()
-> 1089     return [x for x in seq if x not in seen and not seen.add(x)]
  1090
  1091 class UniqueAppender(object):

TypeError: unhashable type: 'list'


--
David Gardner
Pipeline Tools Programmer
Jim Henson Creature Shop
dgard...@creatureshop.com


--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to