On Apr 1, 2010, at 7:45 PM, David Gardner wrote:

> 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__?

oh.  interesting problem, yeah.  query is uniqing the values returned and 
assumes they are all hashable - it does this when any of the items in the row 
are full entities (i.e. your Task here).   I don't know that there's a 
workaround for now other than using a TypeDecorator that turns the returned 
list into a tuple.




> 
> 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
> [email protected]
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.
> 

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

Reply via email to