3 Aug 2012 21:22
query .all and .count return different results when used with a subquery
kris <kkvilekval <at> gmail.com>
2012-08-03 19:22:26 GMT
2012-08-03 19:22:26 GMT
SA 0.7.8
I am getting some strange results when using a subquery that returns Duplicate
rows. Note in line 7 I am not using distinct, yet I get one object where I would expect
2. Also if I query.count I do actually receive 2.
What's going on here?
Thanks,
kris
kris
vq1 = DBSession.query(Value).filter_by(document_id = 622849)
In [3]: vq1.all()
Out[3]:
[<bq.data_service.model.tag_model.Value object at 0x59a2890>,
<bq.data_service.model.tag_model.Value object at 0x59a2990>]
In [5]: sq1 = vq1.with_labels().subquery()
In [6]: q = DBSession.query (Taggable).filter (Taggable.id == sq1.c.values_valobj)
In [7]: q.all()
Out[7]: [<bq.data_service.model.tag_model.Taggable object at 0x59b0590>]
In [9]: q.count()
Out[9]: 2L
From sql:
select * from values where resource_parent_id = 622849;
resource_parent_id | indx | valstr | valnum | valobj | document_id
--------------------+------+--------+--------+--------+-------------
622849 | 0 | | | 622840 | 622849
622849 | 1 | | | 622840 | 622849
=# select id from taggable, (select * from values where document_id = 622849) as v where taggable.id = v.valobj;
id
--------
622840
622840
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/Y6KJNVstnSYJ.
To post to this group, send email to sqlalchemy <at> googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
RSS Feed