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

marc_s
760k186 gold badges1.4k silver badges1.5k bronze badges
asked Jul 27, 2021 at 5:04
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.

answered Jul 27, 2021 at 5:23
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)
answered Jul 27, 2021 at 5:11

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.