2

Running the code shown here, I get a SQL syntax error, couldn't find the reason:

startEpoch = 1623331800#july 10 7PM ePOCH
EndEpoch = 1624195800#july 20 7PM ePOCH

query = "SELECT `Machine`,`Epoch`,`Time`,`STATE` FROM MSC where `Epoch`>=" + str(startEpoch) + "and `Epoch`<=" + str(EndEpoch) + ";"
df = pd.read_sql(query, db)
df.head(3)

Error:

DatabaseError: Execution failed on SQL 'SELECT Machine,Epoch,Time,STATE FROM MSC where Epoch>=1623331800and Epoch<=1624195800;':

1064 (42000): 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 'Epoch<=1624195800' at line 1

2
  • 1
    1623331800and. Notice anything? Commented Jul 27, 2021 at 5:08
  • ops, my bad !!! Commented Jul 27, 2021 at 5:20

2 Answers 2

2
DatabaseError: Execution failed on SQL 'SELECT Machine,Epoch,Time,STATE FROM MSC where Epoch>=**1623331800and** Epoch<=1624195800;':

behind the condition of the epoch field, I think the error will resolve if you add 1 space before the "and" character.

Sign up to request clarification or add additional context in comments.

Comments

1

The AND keyword concat with the value 1623331800and

Try the below:

startEpoch = 1623331800#july 10 7PM ePOCH
EndEpoch = 1624195800#july 20 7PM ePOCH

query = "SELECT `Machine`,`Epoch`,`Time`,`STATE` FROM MSC where `Epoch`>= " + str(startEpoch) + " and `Epoch`<= " + str(EndEpoch) + ";"
df = pd.read_sql(query, db)
df.head(3)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.