2017-12-08 1 views
1

Ich habe eine Tabelle product_option_param genannt, die eine Spalte hat POVs von JSON-Typ, die im Grunde JSON-Arrays mit IDs (zB [1,2,3]) hältMySQL json_remove gibt null zurück

Wenn ich löschen müssen, für beispielsweise eine ID , führe ich diese:

UPDATE product_option_param 
SET povs = JSON_REMOVE(
    povs, replace(JSON_SEARCH(povs, 'one', 1), '"', '') 
) 
WHERE json_search(povs, 'one', 1) IS NOT NULL 

Aber es stellt sich nur alle Zellen, die im Array in null haben. Was mache ich falsch?

Antwort

0

Versuchen:

SET @`id` := '1'; 

UPDATE `product_option_param` 
SET `povs` = 
    JSON_REMOVE(
    `povs`, 
    JSON_UNQUOTE(
     JSON_SEARCH(
     REPLACE(
      REPLACE(
      REPLACE(
       `povs`, 
       '[', 
       '["' 
      ), 
      ']', 
      '"]' 
     ), 
      ',', 
      '","' 
     ), 
     'one', 
     @`id` 
    ) 
) 
) 
WHERE 
    JSON_CONTAINS(`povs`, @`id`); 

db-fiddle See.