[Django] #29491: Query.get_count produces SQL that is invalid for DB2

9 views
Skip to first unread message

Django

unread,
Jun 13, 2018, 2:26:55 PM6/13/18
to django-...@googlegroups.com
#29491: Query.get_count produces SQL that is invalid for DB2
-------------------------------------+-------------------------------------
Reporter: Paul | Owner: nobody
Wujek |
Type: Bug | Status: new
Component: Database | Version: 2.0
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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).
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29491>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 13, 2018, 4:09:43 PM6/13/18
to django-...@googlegroups.com
#29491: Query.get_count produces SQL that is invalid for DB2
-------------------------------------+-------------------------------------
Reporter: Paul Wujek | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (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

{{{#!python
SELECT COUNT(*) AS `__count` FROM `table`
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29491#comment:1>

Django

unread,
Jun 15, 2018, 2:25:18 PM6/15/18
to django-...@googlegroups.com
#29491: Query.get_count produces SQL that is invalid for DB2
-------------------------------------+-------------------------------------
Reporter: Paul Wujek | Owner: Jeff
Type: Bug | Status: assigned

Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jeff):

* owner: nobody => Jeff
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/29491#comment:2>

Django

unread,
Jun 15, 2018, 7:51:08 PM6/15/18
to django-...@googlegroups.com
#29491: Query.get_count produces SQL that is invalid for DB2
-------------------------------------+-------------------------------------
Reporter: Paul Wujek | Owner: Jeff
Type: Bug | Status: closed

Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: assigned => closed
* resolution: => wontfix


Comment:

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

--
Ticket URL: <https://code.djangoproject.com/ticket/29491#comment:3>

Reply all
Reply to author
Forward
0 new messages