Menu

Erroneous error with "count" aggregate query

JanErics
2007-08-18
2012-09-19
  • JanErics

    JanErics - 2007-08-18

    I've not been able to get count aggregates to work with the 1.2.2 or 1.2.2c1 versions connecting to a MySQL version: 4.1.12.

    The code is:

    long_string = "SELECT sleuth_Testcase.tcName, \ sleuth_Testcase.tcPass, \ COUNT (sleuth_Testcase.tcPass) \ FROM sleuth_Testcase \ GROUP BY sleuth_Testcase.tcPass"
    cursor.execute (long_string)

    The result is:

    Traceback (most recent call last):
    File "C:\Documents and Settings\schnellman\D\Python\Query4F.py", line 30, in <module>
    cursor.execute (long_string)
    File "C:\Python25\lib\site-packages\MySQLdb\cursors.py", line 166, in execute
    self.errorhandler(self, exc, value)
    File "C:\Python25\lib\site-packages\MySQLdb\connections.py", line 35, in defaulterrorhandler
    raise errorclass, errorvalue
    ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(sleuth_Testcase.tcPass) FROM sleuth_Testcase GROUP BY sleuth_Testcase.tcPass' at line 1")

    However, if the select is sent directly to MySQL with the Python syntax removed, it works. I ran more than 10 different single and multi-table queries and all failed.

    Other queries, using other aggregate functions like SUM and AVG work fine, both directly to the MySQL server and through Python.

     
    • Andy Dustman

      Andy Dustman - 2007-08-20

      If it's an SQL syntax error, it cannot be a problem with MySQLdb.

      Try removing the space between "COUNT" and "(".

       
    • JanErics

      JanErics - 2007-08-21

      This is a compatibility issue. I'm a long-term SQL 2000 and SQL 2005 user and add a spcae between count and (). I found that by setting the mode, the errors disappeared.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.