JSONカラムを扱うmysql 5.7用の新しいAPIを試しています。私test
列には、次のようになります。mysql 5.7ネストされたjsonオブジェクトにキー/値を追加する
{"foo":{"efg":1}, "bar":{"abc":0}}
私がやりたいそれは何"foo":{"efg":1, "klm":2}
になりますので、たとえばfoo
ため、鍵の一つに追加されます。私はtheir documentation以下、これまでに試した:
mysql> select json_insert(test, '$.foo', 10, '$.foo.klm', 2) from table1
where name='Joe';
それは何して"efg":1
を交換し、結果は"foo":{"klm":2}
です。
mysql> select json_array_append(test, '$.foo', '{"klm":2}') from table1 where
name="Joe';
上の行は、明らかに私が欲しいものではありません配列"foo":[{"efg":1}, {"klm":2}]
、にfoo
を変換します。
私は、クエリを一緒に組み合わせて試してみた:
mysql> select json_insert(test, '$.foo', 10, '$.foo',
select json_merge(select json_extract(test, '$.foo') from table1
where name="Joe"), '{"klm":2}') from table1 where name="Joe";
ちょうど私に構文エラーnear select json_extract(test, '$.foo')
を与えること。
アドバイスをいただければ幸いです。
あるべき '{ "FOO":{ "EFG":1、 "KLM":2}、" bar ":{" abc ":0}}'。それらのドキュメントは主に配列の変更で動作しますが、すべてをObjectとして保持したいと思います。 – denikov
私は、あなたの 'json_insert'を使って正確な結果を得ています(あるいは' name = 'Joe'; table1から 'json_insert(test、 '$ .foo.klm'、2)を選択してください; –
@JoachimIsaksson私はあなたのコメントのようないくつかのパラメータを出し、 '' foo ''オブジェクトの全てを置き換えています。 – denikov