メインコンテンツまでスキップ
翻訳ページ

このページは AI の支援を受けて英語から翻訳されています。内容が異なる場合は英語版が正となります。

JSON_REPLACE

パスに基づいて JSON オブジェクト内の既存の値を更新します。JSON_REPLACE はドキュメントに新しいキーを追加せず、既存のキーの値のみを置き換えます。

関連項目:
[SELECT] [JSON_EXTRACT] [JSON_SET] [JSON_REPLACE]


構文​

SELECT JSON_REPLACE(json_column, path, new_value) FROM <multipartIdentifier>;

引数​

json_column
値を置き換える対象の JSON 列または式。

path
JSON ドキュメント内で置き換えを行う位置を指す JSON パス式。パスは既存のキーを指している必要があります。

new_value
JSON ドキュメントの指定したパスで置き換える新しい値。

戻り値​

指定した値を置き換えた、変更後の JSON ドキュメントを返します。指定したパスが存在しない場合は、元の JSON ドキュメントが変更されずに返されます。

キーが存在する場合の動作
関数すでに存在する場合に上書き存在しない場合に作成
json_insert()いいえはい
json_replace()はいいいえ
json_set()はいはい

例​

JSON オブジェクト内の単一の値を置き換える​

SELECT sku as original,
JSON_REPLACE(sku, '$.name', 'Standard_EU') as updated
FROM azure.container_registry.registries
WHERE registry_name = 'exampleRegistryProd'
AND subscription_id = '12345678-abcd-1234-abcd-1234abcd5678'
AND resource_group_name = 'exampleResourceGroupProd';
/* expected output...
|---------------------------------------|------------------------------------------|
| original | updated |
|---------------------------------------|------------------------------------------|
| {"name":"Standard","tier":"Standard"} | {"name":"Standard_EU","tier":"Standard"} |
|---------------------------------------|------------------------------------------|
*/

JSON オブジェクト内の複数の値を置き換える​

select
properties beforechange,
json_replace(json_remove(properties,
'$.allowPort25Out',
'$.auxiliarySku',
'$.provisioningState',
'$.resourceGuid',
'$.macAddress',
'$.vnetEncryptionSupported',
'$.enableIPForwarding',
'$.defaultOutboundAccess',
'$.primary',
'$.virtualMachine',
'$.hostedWorkloads',
'$.tapConfigurations',
'$.nicType',
'$.auxiliaryMode',
'$.ipConfigurations[0].id',
'$.ipConfigurations[0].etag',
'$.ipConfigurations[0].type',
'$.ipConfigurations[0].properties.provisioningState',
'$.ipConfigurations[0].properties.privateIPAddress',
'$.ipConfigurations[0].properties.privateIPAllocationMethod',
'$.ipConfigurations[0].properties.primary',
'$.ipConfigurations[0].properties.privateIPAddressVersion'
),
'$.ipConfigurations[0].name',
'vmss-flex-vnet-nic01-defaultIpConfiguration'
) afterchange
from
azure.network.network_interfaces
where subscription_id = '0123456789'
and resource_group_name = 'vm-rg'
and network_interface_name = 'vm1450_z1'