{"id":92,"date":"2009-11-20T15:18:24","date_gmt":"2009-11-20T21:18:24","guid":{"rendered":"http:\/\/thenoyes.com\/littlenoise\/?p=92"},"modified":"2009-11-20T15:18:24","modified_gmt":"2009-11-20T21:18:24","slug":"group-unconcat","status":"publish","type":"post","link":"https:\/\/thenoyes.com\/littlenoise\/?p=92","title":{"rendered":"GROUP UNCONCAT"},"content":{"rendered":"<p>Dunno why you&#8217;d rather do this in SQL than in your application layer, but if you do, here&#8217;s one way to turn a delimited string of values back into multiple rows &#8211; just the opposite of GROUP_CONCAT:<\/p>\n<pre>SET @sourceString = 'a,b,c,d,e';\r\nSET @sql = CONCAT('INSERT INTO t VALUES (\\\\'', REPLACE(@sourceString, ',', '\\\\'),(\\\\''), '\\\\')');\r\nPREPARE myStmt FROM @sql;\r\nEXECUTE myStmt;<\/pre>\n<p>Just to show what&#8217;s going on:<\/p>\n<pre>mysql> SELECT @sql;\r\n+----------------------------------------------------+\r\n| @sql                                               |\r\n+----------------------------------------------------+\r\n| INSERT INTO t VALUES ('a'),('b'),('c'),('d'),('e') |\r\n+----------------------------------------------------+\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Dunno why you&#8217;d rather do this in SQL than in your application layer, but if you do, here&#8217;s one way to turn a delimited string of values back into multiple rows &#8211; just the opposite of GROUP_CONCAT: SET @sourceString = &#8216;a,b,c,d,e&#8217;; SET @sql = CONCAT(&#8216;INSERT INTO t VALUES (\\\\&#8221;, REPLACE(@sourceString, &#8216;,&#8217;, &#8216;\\\\&#8217;),(\\\\&#8221;), &#8216;\\\\&#8217;)&#8217;); PREPARE myStmt [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[4],"tags":[],"class_list":["post-92","post","type-post","status-publish","format-standard","hentry","category-mysql"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2IBF1-1u","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/92","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=92"}],"version-history":[{"count":0,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/92\/revisions"}],"wp:attachment":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=92"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=92"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=92"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}