{"id":6051,"date":"2020-03-02T10:38:56","date_gmt":"2020-03-02T15:38:56","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=6051"},"modified":"2020-03-02T10:38:56","modified_gmt":"2020-03-02T15:38:56","slug":"mysql-moving-data-from-one-table-to-another","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=6051","title":{"rendered":"MySQL: Moving Data From One Table To Another"},"content":{"rendered":"<p>Our OpenHAB persistence data is stored in MySQL. There&#8217;s an &#8220;items&#8221; table which correlates each ItemName string to an ItemID integer. There are then Item#### tables that store persistence data for each item. If you rename an item, this means a new table is created and previous persistence data is no longer associated with the item. For some items, that&#8217;s fine &#8212; I don&#8217;t <em>really<\/em> care when the office light was on last month. But there&#8217;s persistence data that we use over a long term &#8212; outdoor temperature, luminance, electrical usage. In these cases, we want to pull the old data into the new table. There&#8217;s a quick one-liner SQL command that accomplishes this:<\/p>\n<p>INSERT INTO NewTable SELECT * from OldTable;<br \/>\ne.g. INSERT INTO Item3857 SELECT * FROM Item3854;<\/p>\n<p>You can drop the old table too:<\/p>\n<p>DROP OldTable;<\/p>\n<p>But I run a <a href=\"https:\/\/www.rushworth.us\/lisa\/?p=1564\">cleanup script against the item list<\/a> so often don&#8217;t bother to remove tables one-off.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Our OpenHAB persistence data is stored in MySQL. There&#8217;s an &#8220;items&#8221; table which correlates each ItemName string to an ItemID integer. There are then Item#### tables that store persistence data for each item. If you rename an item, this means a new table is created and previous persistence data is no longer associated with the &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[56,44,394,317,922],"class_list":["post-6051","post","type-post","status-publish","format-standard","hentry","category-system-administration","tag-mysql","tag-openhab","tag-openhab2","tag-persistence","tag-sql"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/6051","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6051"}],"version-history":[{"count":1,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/6051\/revisions"}],"predecessor-version":[{"id":6052,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/6051\/revisions\/6052"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6051"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6051"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6051"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}