pymysql.err.ProgrammingError Error while Inserting Row into MySQL table (using Python, Flask, ClearDB)

apaul

I have seen numerous posts about this but I have not been able to fix this issue. I am converting my database from SQLite to MySQL and am having an issue when inserting values into a table. In this statement, the keyword and sortType are variables that are passed into the method and not modified. keyword, type_search, and sort are of type TEXT while date_add is of type DATE.

conn = mysql.connect() 
cursor = conn.cursor() 
cursor.execute('INSERT INTO search (keyword, date_add, type_search, sort) VALUES (%s, date(), %s, %s)', (keyword, 'value', sortType))
conn.commit()

Error:

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 '), 'value', 'views_week')' at line 1")

I changed date to date_add as it was a keyword but this did not fix the issue. How can I fix this?

Thanks!

Doyle B

You could also create the table with the column default of the current timestamp:

create table search (
keyword...,
date_add TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
...)

Then you could do the execute without mentioning the date_add column and it will be the current timestamp.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Error while using pymysql in flask

MYSQL Database error: "pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your-"

Mysql Syntax error while inserting from Servlet using preparedstatement

Inserting a list holding multiple values in MySQL using pymysql

Inserting row into Postgresql using python

Python mysql.connector error while inserting boolean into mysql database

Getting Error 10293 while inserting a row to a hive table having array as one of the fileds

Get error ProgrammingError when insert to MySQL database using Python

Error Inserting Data into Table using MySQL

raise err.ProgrammingError("execute() first") pymysql.err.ProgrammingError: execute() first

MySql: Inserting python lists into a table

How to solve pymysql.err.programmingError during upload using pymysql

Mysql, Issue with inserting a row into a table

nodejs mysql module error while inserting row

Searching a MySQL Database on ClearDB using Python script

Receiving "No Such Table" error while trying to access existing MySQL database using Flask and SQLAlchemy

Error inserting values to a table in MySql

Exception while inserting mysql table

Inserting into MySQL table using a variable

MySQL Table not created using Flask and PyMySQL

Inserting into a table in mysql using query

Python pymysql syntax error while inserting a JSON object

Error while Inserting Python List to Mysql

Insert record into mysql table using python : ProgrammingError: Not enough parameters for the SQL statement

ProgrammingError while trying to insert data into a MySQL table using Python

pymysql.err.programmingError: (1064)

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

MySQL Python connector error while inserting

pymysql.err.OperationalError 2006 on a flask app