Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

PYMYSQL ERROR pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax ")

Here is the full error

Traceback (most recent call last):
  File "Desktop/Work/RDS_LAMDA_Stuff/RDS_Node_Stuff/test.py", line 26, in <module>
    handler()
  File "Desktop/Work/RDS_LAMDA_Stuff/RDS_Node_Stuff/test.py", line 17, in handler
    cursor.execute('SELECT * FROM Reads')
  File "Desktop/Work/RDS_LAMDA_Stuff/RDS_Node_Stuff/pymysql/cursors.py", line 148, in execute
    result = self._query(query)
  File "Desktop/Work/RDS_LAMDA_Stuff/RDS_Node_Stuff/pymysql/cursors.py", line 310, in _query
    conn.query(q)
  File "Desktop/Work/RDS_LAMDA_Stuff/RDS_Node_Stuff/pymysql/connections.py", line 548, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "Desktop/Work/RDS_LAMDA_Stuff/RDS_Node_Stuff/pymysql/connections.py", line 775, in _read_query_result
    result.read()
  File "Desktop/Work/RDS_LAMDA_Stuff/RDS_Node_Stuff/pymysql/connections.py", line 1156, in read
    first_packet = self.connection._read_packet()
  File "Desktop/Work/RDS_LAMDA_Stuff/RDS_Node_Stuff/pymysql/connections.py", line 725, in _read_packet
    packet.raise_for_error()
  File "Desktop/Work/RDS_LAMDA_Stuff/RDS_Node_Stuff/pymysql/protocol.py", line 221, in raise_for_error
    err.raise_mysql_exception(self._data)
  File "Desktop/Work/RDS_LAMDA_Stuff/RDS_Node_Stuff/pymysql/err.py", line 143, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.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 'Reads' at line 1")

For context here is my code

from multiprocessing import connection
import pymysql
from pymysql.cursors import Cursor

# RDS config
endpoint = '********'
username = '********'
password = '********'
database_name = '*********'

#connection config

connection = pymysql.connect(host=endpoint,user=username,passwd=password,db=database_name)

def handler():
    cursor = connection.cursor()
    cursor.execute('SELECT * FROM Reads')

    rows = cursor.fetchall()

    for row in rows:
        print("{0} {1} {2} {3}".format(row[0], row[1], row[2], row[3]))



handler()

I have 2 other tables in my database which work fine when i query them however this table seems to be the only one causing an error.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Feel free to ask for more if this is too vague

>Solution :

It’s worth checking manual in cases like this – and Reads is a reserved word therefore must be backticked – better still don’t use reserved words or you will forever have to remember to backtick in code..

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading