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)

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

Download all attachments as: .zip

Change History (7)

comment:1 by adamfast, 16 years ago

Triage Stage: UnreviewedDesign decision needed

comment:2 by Samuel Cormier-Iijima, 16 years ago

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

queryset.extra(tables={
    'k': '(select * from table)'
})

by Samuel Cormier-Iijima, 16 years ago

Attachment: 7907.patch added

comment:3 by Shaun Cutts, 14 years ago

Cc: shaun@… added

by Shaun Cutts, 14 years ago

Attachment: 7907_2.diff added

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

comment:4 by Luke Plant, 14 years ago

Severity: Normal
Type: New feature

comment:5 by Jacob, 13 years ago

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