Opened 6 years ago

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

Description

This bug occurs in db/models/sql/query.py

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:

SELECT COUNT(*) AS __count FROM MYTABLE

Error Returned:

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

Cause:
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 by Simon Charette, 6 years ago

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 by Jeff, 6 years ago

Owner: changed from nobody to Jeff
Status: newassigned

comment:3 by Tim Graham, 6 years ago

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