Hello Mike,
On Tue, 05 May 2015 21:09:31 +0200, Mike Bayer <[email protected]>
wrote:
On 5/5/15 1:17 PM, Brecht Machiels wrote:
Oops, was a bit too quick there...
Here's the echo='debug' output:
2015-05-05 19:16:11,528 INFO sqlalchemy.engine.base.Engine SELECT *
FROM group_counts WHERE group_id = 1
2015-05-05 19:16:11,528 INFO sqlalchemy.engine.base.Engine ()
2015-05-05 19:16:11,528 DEBUG sqlalchemy.engine.base.Engine Col
('group_id', 'value', 'count')
2015-05-05 19:16:11,528 DEBUG sqlalchemy.engine.base.Engine Row (1, 1,
6)
2015-05-05 19:16:11,528 DEBUG sqlalchemy.engine.base.Engine Row (1, 2,
12)
2015-05-05 19:16:11,528 DEBUG sqlalchemy.engine.base.Engine Row (1, 3,
103)
versus
2015-05-05 19:16:11,529 INFO sqlalchemy.engine.base.Engine SELECT
group_counts.group_id AS group_counts_group_id, group_counts.value AS
group_counts_value, group_counts.count AS group_counts_count
FROM group_counts
WHERE group_counts.group_id = ?
2015-05-05 19:16:11,529 INFO sqlalchemy.engine.base.Engine (1,)
2015-05-05 19:16:11,529 DEBUG sqlalchemy.engine.base.Engine Col
('group_counts_group_id', 'group_counts_value', 'group_counts_count')
2015-05-05 19:16:11,529 DEBUG sqlalchemy.engine.base.Engine Row (1, 1,
6)
2015-05-05 19:16:11,530 DEBUG sqlalchemy.engine.base.Engine Row (1, 2,
12)
2015-05-05 19:16:11,530 DEBUG sqlalchemy.engine.base.Engine Row (1, 3,
103)
Only the first item is returned, however.
these two queries are against the same table. I thought we were
comparing the SELECT results from a set of real tables vs. views?
No, these are queries against the same view.
I'm not yet looking at what the specifics are yet, but keep in mind the
ORM only returns full objects for rows that have a full primary key
*and* it deduplicates on primary key, because we use an identity map.
So if above, "group_counts_group_id" is your primary key, the ORM has no
choice but to give you only one object back.
That was indeed the problem. I didn't know about deduplication. After
overriding the view's 'value' column to flag it as a primary key, things
work as expected.
While that works for me, I'm wondering if it is possible to alter a
table's columns after creation. In that case, I could reflect the view and
afterwards set the primary_key flag on the relevant columns. This would
avoid some code duplication.
In any case, thank you for your time!
Brecht
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.