Code

Opened 4 years ago

Closed 3 years ago

Last modified 14 months ago

#13159 closed (fixed)

Quote aggregate alias in order by

Reported by: davidelias Owned by:
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: UI/UX:

Description

Running the aggregation tests gives an error against Firebird database.

>>> qs = Book.objects.values_list('price').annotate(count=Count('price')).order_by('-count', 'price')

Produces the following sql:

SELECT "AGGREGATION_BOOK"."PRICE", COUNT("AGGREGATION_BOOK"."PRICE") AS "COUNT" FROM "AGGREGATION_BOOK" GROUP BY "AGGREGATION_BOOK"."PRICE" ORDER BY count DESC, "AGGREGATION_BOOK"."PRICE" ASC

count in order by clause is not quoted and clashed with reserved the corresponding reserved word.

Tested the patch against MySQL and SQLite.

Attachments (1)

quote_aggregate_alias_orderby.patch (552 bytes) - added by davidelias 4 years ago.

Download all attachments as: .zip

Change History (7)

Changed 4 years ago by davidelias

comment:1 Changed 4 years ago by russellm

  • milestone 1.2 deleted
  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Not critical for 1.2. Patch also requires a test case.

comment:2 Changed 4 years ago by russellm

  • milestone set to 1.3

Marking against 1.3 so it isn't forgotten.

comment:3 Changed 3 years ago by Alex

  • Resolution set to fixed
  • Status changed from new to closed

(In [15318]) Fixed #13159 -- properly quote aggregates in order_by.

comment:4 Changed 3 years ago by Alex

(In [15319]) [1.2.X] Fixed #13159 -- properly quote aggregates in order_by. Backport of [15318].

comment:5 Changed 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

comment:6 Changed 14 months ago by akaariai

  • Component changed from ORM aggregation to Database layer (models, ORM)

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.