Re: [sqlalchemy] array_agg() in ORM entities (0.5.8)?

2010-04-02 Thread David Gardner
I was able to come up with a work-around, since this is part of a 
report, I was able to format the dates as strings

the way I was planning to do in python anyways:

qry=session.query(Task, 
func.cat(func.to_char(TaskHistory.updated,'MM/DD/YY HH:MI am')))


This works well for my needs (cat() isn't a standard Postgres aggregate, 
but instead something I wrote up in plpgsql).






Michael Bayer wrote:
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.



--
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.



[sqlalchemy] array_agg() in ORM entities (0.5.8)?

2010-04-01 Thread David Gardner
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.priority5).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.



Re: [sqlalchemy] array_agg() in ORM entities (0.5.8)?

2010-04-01 Thread Michael Bayer

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.priority5).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.
 

-- 
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.