Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wr.mysql.to_sql with use_column_names=True when column names are reserved words #918

Closed
DonnaArt opened this issue Sep 21, 2021 · 1 comment · Fixed by #919
Closed

wr.mysql.to_sql with use_column_names=True when column names are reserved words #918

DonnaArt opened this issue Sep 21, 2021 · 1 comment · Fixed by #919
Labels
bug Something isn't working minor release Will be addressed in the next minor release ready to release
Milestone

Comments

@DonnaArt
Copy link
Contributor

Describe the bug

I'm looking to use AWS Data Wrangler to read data from s3 files, process it, and insert into RDS MySQL. The source of the s3 files is another RDS database (via DBMS). I am not involved in the schema of the source, and on some of the tables reserved words have been used as column names - in this example it is 'set', but others such as 'group' are used in other tables.

I'm having an issue when inserting these records into the target RDS (at this point as a copy of the source data, without columns added by processing in the Lambda), caused by the use of a reserved word.

I'd like to keep the columns the same as the source where possible - is there a way for me to achieve this?

wr.mysql.to_sql(df, con_mysql, schema=db, table=tab, mode="upsert_duplicate_key", index=False, chunksize=200, use_column_names=True)

[DEBUG] 2021-09-21T09:26:53.098Z eca30ba2-d2ff-4a1b-90dd-3f418901d090 sql: INSERT INTO db.table (timestamp, id, set, parentid, name, value, file_record_number, dlk_rnk, dlk_updatedat, rnk) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE timestamp=VALUES(timestamp), id=VALUES(id), set=VALUES(set), parentid=VALUES(parentid), name=VALUES(name), value=VALUES(value), file_record_number=VALUES(file_record_number), dlk_rnk=VALUES(dlk_rnk), dlk_updatedat=VALUES(dlk_updatedat), rnk=VALUES(rnk)

[ERROR] 2021-09-21T09:26:53.103Z eca30ba2-d2ff-4a1b-90dd-3f418901d090 (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 'set, parentid, name, value, file_record_number, dlk_rnk, dlk_updatedat, rnk) VAL' at line 1")

With backticks added to column names of the dataframe:
df = df.rename(columns=lambda x: '' + x + '')

[DEBUG] 2021-09-21T10:06:38.475Z ed54a68e-b76a-4fb9-84df-fa27c6eeb2d3 sql: INSERT INTO db.table (timestamp, id, set, parentid, name, value, file_record_number, dlk_rnk, dlk_updatedat, rnk) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE timestamp=VALUES(timestamp), id=VALUES(id), set=VALUES(set), parentid=VALUES(parentid), name=VALUES(name), value=VALUES(value), file_record_number=VALUES(file_record_number), dlk_rnk=VALUES(dlk_rnk), dlk_updatedat=VALUES(dlk_updatedat), rnk=VALUES(rnk)

[ERROR] 2021-09-21T10:06:38.484Z ed54a68e-b76a-4fb9-84df-fa27c6eeb2d3 (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 'timestamp=VALUES(timestamp), id=VALUES(id), set=VALUES(set``' at line 1")

With quotation marks added to column names:
df = df.rename(columns=lambda x: '"' + x + '"')

[DEBUG] 2021-09-21T10:08:18.733Z 4f75c982-07ec-496d-8231-00abc5760375 sql: INSERT INTO db.table ("timestamp", "id", "set", "parentid", "name", "value", "file_record_number", "dlk_rnk", "dlk_updatedat", "rnk") VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s), (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE "timestamp"=VALUES("timestamp"), "id"=VALUES("id"), "set"=VALUES("set"), "parentid"=VALUES("parentid"), "name"=VALUES("name"), "value"=VALUES("value"), "file_record_number"=VALUES("file_record_number"), "dlk_rnk"=VALUES("dlk_rnk"), "dlk_updatedat"=VALUES("dlk_updatedat"), "rnk"=VALUES("rnk")

[ERROR] 2021-09-21T10:08:18.745Z 4f75c982-07ec-496d-8231-00abc5760375 (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 '"timestamp", "id", "set", "parentid", "name", "value", "file_record_number", "dl' at line 1')

Environment

v 2.11.0 of AWS data wrangler, AWS Lambda Python 3.8 runtime. Target is Aurora RDS MySQL 5.7.

@DonnaArt DonnaArt added the bug Something isn't working label Sep 21, 2021
@jaidisido
Copy link
Contributor

That is fair enough, thanks for the contribution. PR merged. It will be available in the next release

@jaidisido jaidisido added this to the 2.12.0 milestone Sep 28, 2021
@jaidisido jaidisido linked a pull request Sep 28, 2021 that will close this issue
@jaidisido jaidisido added minor release Will be addressed in the next minor release ready to release labels Sep 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working minor release Will be addressed in the next minor release ready to release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants