dgraph icon indicating copy to clipboard operation
dgraph copied to clipboard

Escape MySQL column names

Open andres-lowrie opened this issue 4 years ago • 3 comments

This change wraps all the column names with backticks so that MySQL won't complain when a table has columns that are also reserved keywords in MySQL.


This change is Reviewable

andres-lowrie avatar Jan 25 '20 18:01 andres-lowrie

I was migrating a database that uses MySQL reserved keywords for column names thus the migrate tool was showing the following MySQL error when trying to reference said column in a query:

while writing data file: while dumping table food: Error 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 'groups,id,in_fndds,long_description,manufacturers,refuse_description,refuse_perc' at line 1

The problem was with the column name groups, this I figured surrounding the column name with backticks should allow users to easier migrate a larger variety of MySQL tables.

andres-lowrie avatar Jan 25 '20 18:01 andres-lowrie

Reviewed 1 of 1 files at r2. Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @andres-lowrie and @manishrjain)

dgraph/cmd/migrate/dump.go, line 95 at r2 (raw file):

Quoted 4 lines of code… using the same logic twice. This could be wrapped in a method.

I put in a function instead of method out of habit and figured that the wrapping logic was generic enough, idk

If this should be method I'm glad to change it

andres-lowrie avatar Feb 01 '20 21:02 andres-lowrie

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Apr 29 '22 07:04 CLAassistant

Feel free to re-open this PR against main, closing it for now. Thank you for the PR.

mangalaman93 avatar Aug 11 '23 02:08 mangalaman93