Downdog555
Downdog555

Reputation: 31

Correct SQL usage in Python Using PYMYSQL

I am attempting to write a SQL in python using PYMYSQL, which searches a table for a certain record with a set value, however while this sounds simple I cannot seem to do it below is my query:

SELECT Series_ID FROM series_information WHERE Series_Name "'+data +'"'

where the data is the value that I am searching for however the following error occurs:

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 \'"Spice And Wolf"\' at line 1')

The problem I believe is that I am not sure how to properly escape the data value if it has spaces in it and therefore would require quotation marks in the SQL query.

Upvotes: 1

Views: 257

Answers (2)

iceraj
iceraj

Reputation: 359

`SELECT Series_ID FROM series_information WHERE Series_Name "'+data +'"'`

Is not a valid SQL query did you mean:

`'SELECT Series_ID FROM series_information WHERE Series_Name like "'+data +'"'`

Upvotes: 0

blasko
blasko

Reputation: 690

You're missing a comparison (like, =, etc) between Series_Name and data, as well as a ';' on the end of the query.

`'SELECT Series_ID FROM series_information WHERE Series_Name = "'+data +'";'

Upvotes: 1

Related Questions