Opened 10 years ago

Closed 6 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: master
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


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.


Attachments (2)

7907.patch (1.7 KB) - added by Samuel Cormier-Iijima 10 years ago.
7907_2.diff (1.9 KB) - added by Shaun Cutts 8 years ago.
update of the previous patch -- conforms to new sql compilation

Download all attachments as: .zip

Change History (7)

comment:1 Changed 10 years ago by adamfast

Triage Stage: UnreviewedDesign decision needed

comment:2 Changed 10 years ago by Samuel Cormier-Iijima

Cc: sciyoshi@… added
Component: Core frameworkDatabase wrapper
Has patch: set
Keywords: post-qsrf added
Needs documentation: set
Needs tests: set

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

    'k': '(select * from table)'

Changed 10 years ago by Samuel Cormier-Iijima

Attachment: 7907.patch added

comment:3 Changed 8 years ago by Shaun Cutts

Cc: shaun@… added

Changed 8 years ago by Shaun Cutts

Attachment: 7907_2.diff added

update of the previous patch -- conforms to new sql compilation

comment:4 Changed 7 years ago by Luke Plant

Severity: Normal
Type: New feature

comment:5 Changed 6 years ago by Jacob

Easy pickings: unset
Resolution: wontfix
Status: newclosed
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.
Back to Top