On 6 syys, 11:22, Alex Hill <[email protected]> wrote: > Hi Anssi, > > Thanks for your feedback! Responses inline. > > 1. It should not be assumed that the primary key is the field needed > > > in the inner query. We do have foreign keys to other fields, and one > > can use this approach without foreign keys at all. > > Hmm, yes. Thinking about it, this seems like the biggest obstacle to > implementing the query-wrapping approach. > > The reason I proposed just selecting the PK was to mirror the behaviour of > QuerySet when passed to __in, as happens here: > > https://github.com/django/django/blob/master/django/db/models/query.p... > > But since we're talking about raw SQL, we'd want maximum flexibility - so > would we need to introduce a ValuesRawQuerySet in order to select arbitrary > columns? It seems that would be the approach that most closely mirrors > QuerySet.
The ValuesRawQuerySet might be a good idea. Granted, the use cases for it are hard to come by apart of support for subqueries... One might say we have implemented a really fancy way to do cursor.execute(); cursor.fetchall()... :) Another way is to have a pre_subselect hook, and wrap the raw SQL with the right column selected automatically using that. - Anssi -- You received this message because you are subscribed to the Google Groups "Django developers" 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/django-developers?hl=en.
