{"id":615,"date":"2015-03-25T07:58:24","date_gmt":"2015-03-25T07:58:24","guid":{"rendered":"http:\/\/www.nikola-breznjak.com\/blog\/?p=615"},"modified":"2015-08-20T11:59:09","modified_gmt":"2015-08-20T11:59:09","slug":"update-field-only-if-its-new-value","status":"publish","type":"post","link":"https:\/\/nikola-breznjak.com\/blog\/quick-tips\/update-field-only-if-its-new-value\/","title":{"rendered":"Update field only if it&#8217;s new value"},"content":{"rendered":"<p>Recently I wanted to find out how to update field only if the updated value would be new (as in &#8211; different from the current one).<\/p>\n<p>After a bit of googling I managed to find the solution which I&#8217;m now presenting here for anyone that may need a solution for such an use case:<\/p>\n<pre class=\"lang:default decode:true\">UPDATE table SET db_field=(CASE db_field\u00a0WHEN NULL THEN 'new_value' ELSE db_field\u00a0END);<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently I wanted to find out how to update field only if the updated value would be new (as in &#8211; different from the current one). After a&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1335,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"class_list":["post-615","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-quick-tips"],"_links":{"self":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/615","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/comments?post=615"}],"version-history":[{"count":5,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/615\/revisions"}],"predecessor-version":[{"id":2141,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/615\/revisions\/2141"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media\/1335"}],"wp:attachment":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media?parent=615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/categories?post=615"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/tags?post=615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}