{"action":"closed","issue":{"url":"https://api.github.com/repos/PyMySQL/PyMySQL/issues/394","labels_url":"https://api.github.com/repos/PyMySQL/PyMySQL/issues/394/labels{/name}","comments_url":"https://api.github.com/repos/PyMySQL/PyMySQL/issues/394/comments","events_url":"https://api.github.com/repos/PyMySQL/PyMySQL/issues/394/events","html_url":"https://github.com/PyMySQL/PyMySQL/issues/394","id":118071108,"number":394,"title":"Executemany with ON DUPLICATE KEY","user":{"login":"Arengorn","id":7243783,"avatar_url":"https://avatars.githubusercontent.com/u/7243783?v=3","gravatar_id":"","url":"https://api.github.com/users/Arengorn","html_url":"https://github.com/Arengorn","followers_url":"https://api.github.com/users/Arengorn/followers","following_url":"https://api.github.com/users/Arengorn/following{/other_user}","gists_url":"https://api.github.com/users/Arengorn/gists{/gist_id}","starred_url":"https://api.github.com/users/Arengorn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Arengorn/subscriptions","organizations_url":"https://api.github.com/users/Arengorn/orgs","repos_url":"https://api.github.com/users/Arengorn/repos","events_url":"https://api.github.com/users/Arengorn/events{/privacy}","received_events_url":"https://api.github.com/users/Arengorn/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-11-20T16:03:37Z","updated_at":"2015-12-05T01:26:27Z","closed_at":"2015-12-05T01:26:27Z","body":"I've been trying to handle duplicate keys by using `executemany` with an `ON DUPLICATE KEY` statement, but I just cannot get it to work. Is this an issue with PyMySQL or have I coded this wrongly?\r\nThis is what I had:\r\n```python\r\n    # Executes query for each dictionary in member.\r\n    cursor.executemany(\"INSERT INTO `Citizens` (`Handle`,`Org`,`Role`, \"\r\n                       \"`Rank`,`Visibility`,`Stars`,`Type`) VALUES \"\r\n                       \"(%(handle)s,%(sid)s,%(roles)s,%(rank)s,\"\r\n                       \"%(visibility)s,%(stars)s,%(type)s)\", member)\r\n    # Commits changes to the database.\r\n    conn.commit()\r\n```\r\nThis is how I altered it:\r\n```python\r\n    # Executes query for each dictionary in member.\r\n    cursor.executemany(\"INSERT INTO `Citizens` (`Handle`,`Org`,`Role`, \"\r\n                       \"`Rank`,`Visibility`,`Stars`,`Type`) VALUES \"\r\n                       \"(%(handle)s,%(sid)s,%(roles)s,%(rank)s,\"\r\n                       \"%(visibility)s,%(stars)s,%(type)s) ON DUPLICATE\"\r\n                       \" KEY UPDATE `Org`=concat(ifnull(`Org`, \\\"\\\"), \"\r\n                       \"\\\", \\\", %(sid)s);\", member)\r\n    # Commits changes to the database.\r\n    conn.commit()\r\n```\r\nAnd this is the error I have encountered:\r\n```python\r\nThere was a problem inserting member(s): (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 '('real_lethality','000',0,'Master','visible',5,'affiliate') ON DUPLICATE KEY UPD' at line 3\")\r\nWould you like to see the failed SQL query?[Y/n]\r\nb'INSERT INTO `Citizens` (`Handle`,`Org`,`Role`, `Rank`,`Visibility`,`Stars`,`Type`) VALUES \\n(\\'fullmetaljim\\',\\'000\\',\\'Founder\\',\\'Master\\',\\'visible\\',5,\\'main\\') ON DUPLICATE KEY UPDATE `Org`=concat(ifnull(`Org`, \"\"), \", \", \\'000\\'),\\n(\\'real_lethality\\',\\'000\\',0,\\'Master\\',\\'visible\\',5,\\'affiliate\\') ON DUPLICATE KEY UPDATE `Org`=concat(ifnull(`Org`, \"\"), \", \", \\'000\\')\\n;'\r\n```"}}