Opened 2 years ago

Closed 2 years ago

#29491 closed Bug (wontfix)

Query.get_count produces SQL that is invalid for DB2

Reported by: Paul Wujek Owned by: Jeff
Component: Database layer (models, ORM) Version: 2.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


This bug occurs in db/models/sql/

In function get_count lines 5 and 6 are:

        obj.add_annotation(Count('*'), alias='__count', is_summary=True)
        number = obj.get_aggregation(using, ['__count'])['__count']

Code produced looks like:


Error Returned:

[SQL0104] Token _ was not valid. Valid tokens: <IDENTIFIER>. [SQL State=42601, DB Errorcode=-104]

Underscore is not valid as a beginning character for a token in DB2.

Suggested Solution:

Do not use '__count' as a token in the 5th and 6th lines of get_count.
Instead use a token name that does not begin with '_' (Underscore).

Change History (3)

comment:1 Changed 2 years ago by Simon Charette

Is there anyway for the DB2 adapter to quote such identifiers? Would that make them valid?

For example, the MySQL backend's quote_name wraps names in backtips ` resulting the in the following query

SELECT COUNT(*) AS `__count` FROM `table`

comment:2 Changed 2 years ago by Jeff

Owner: changed from nobody to Jeff
Status: newassigned

comment:3 Changed 2 years ago by Tim Graham

Resolution: wontfix
Status: assignedclosed

Closing as wontifx absent justification that the problem can't be fixed in the DB2 backend.

Note: See TracTickets for help on using tickets.
Back to Top