Opened 16 years ago
Closed 13 years ago
#7907 closed New feature (wontfix)
tables argument of QuerySet.extra should be allow a subquery.
Reported by: | bear330 | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | queryset, extra, qn, subquery, post-qsrf |
Cc: | sciyoshi@…, shaun@… | Triage Stage: | Design decision needed |
Has patch: | yes | Needs documentation: | yes |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If I call extra with tables parameter:
queryset.extra(tables=['(select * from table) as k'])
The result SQL will be:
select ........ from `self_table`, `(select * from table) as k`
the subquery will be invalid.
That will be nice if we can determine whether we need qn or not.
For a normal table:
queryset.extra(tables=[qn('tableA'), qn('tableB')])
But for a subquery I can just omit qn to do that.
Thanks.
Attachments (2)
Change History (7)
comment:1 by , 16 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
comment:2 by , 16 years ago
Cc: | added |
---|---|
Component: | Core framework → Database wrapper |
Has patch: | set |
Keywords: | post-qsrf added |
Needs documentation: | set |
Needs tests: | set |
by , 16 years ago
Attachment: | 7907.patch added |
---|
comment:3 by , 14 years ago
Cc: | added |
---|
by , 14 years ago
Attachment: | 7907_2.diff added |
---|
update of the previous patch -- conforms to new sql compilation
comment:4 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → New feature |
comment:5 by , 13 years ago
Easy pickings: | unset |
---|---|
Resolution: | → wontfix |
Status: | new → closed |
UI/UX: | unset |
Now that we've got .raw()
, .extra()
should be used less and less. I'm against adding any more abilities to it -- it's a bad feature and should be used as little as possible.
Note:
See TracTickets
for help on using tickets.
Attaching a patch for one possible solution: allow the
tables
argument to be a dictionary-like object mapping table names to subqueries, where the subquery is not quoted. Your example could therefore be re-written as