번역된 페이지
이 페이지는 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 객체의 여러 값 교체
- 쿼리
- 출력(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'
[{"afterchange":
{
"disableTcpStateTracking": false,
"dnsSettings": {
"appliedDnsServers": [],
"dnsServers": [],
"internalDomainNameSuffix": "02ylkvekgslelowidrppwubzmb.bx.internal.cloudapp.net"
},
"enableAcceleratedNetworking": false,
"ipConfigurations": [
{
"name": "vmss-flex-vnet-nic01-defaultIpConfiguration",
"properties": {
"publicIPAddress": {
"id": "/subscriptions/0123456789/resourceGroups/vm-rg/providers/Microsoft.Network/publicIPAddresses/vm1-ip",
"properties": {
"deleteOption": "Delete"
}
},
"subnet": {
"id": "/subscriptions/0123456789/resourceGroups/vm-rg/providers/Microsoft.Network/virtualNetworks/vm1-vnet/subnets/default"
}
}
}
],
"networkSecurityGroup": {
"id": "/subscriptions/0123456789/resourceGroups/vm-rg/providers/Microsoft.Network/networkSecurityGroups/vm1-nsg"
}
},
"beforechange":
{
"allowPort25Out": false,
"auxiliaryMode": "None",
"auxiliarySku": "None",
"disableTcpStateTracking": false,
"dnsSettings": {
"appliedDnsServers": [],
"dnsServers": [],
"internalDomainNameSuffix": "123ylkvekgslelowidrppwubzmb.bx.internal.cloudapp.net"
},
"enableAcceleratedNetworking": false,
"enableIPForwarding": false,
"hostedWorkloads": [],
"ipConfigurations": [
{
"etag": "123-bc7e-4609-9328-709fe04c69c3",
"id": "/subscriptions/0123456789/resourceGroups/vm-rg/providers/Microsoft.Network/networkInterfaces/vm1450_z1/ipConfigurations/ipconfig1",
"name": "ipconfig1",
"properties": {
"primary": true,
"privateIPAddress": "10.0.0.4",
"privateIPAddressVersion": "IPv4",
"privateIPAllocationMethod": "Dynamic",
"provisioningState": "Succeeded",
"publicIPAddress": {
"id": "/subscriptions/0123456789/resourceGroups/vm-rg/providers/Microsoft.Network/publicIPAddresses/vm1-ip",
"properties": {
"deleteOption": "Delete"
}
},
"subnet": {
"id": "/subscriptions/0123456789/resourceGroups/vm-rg/providers/Microsoft.Network/virtualNetworks/vm1-vnet/subnets/default"
}
},
"type": "Microsoft.Network/networkInterfaces/ipConfigurations"
}
],
"macAddress": "23-0D-3A-1B-FF-91",
"networkSecurityGroup": {
"id": "/subscriptions/0123456789/resourceGroups/vm-rg/providers/Microsoft.Network/networkSecurityGroups/vm1-nsg"
},
"nicType": "Standard",
"primary": true,
"provisioningState": "Succeeded",
"resourceGuid": "566a1d71-923d-41e0-bbd5-d09bf64cbe7b",
"tapConfigurations": [],
"virtualMachine": {
"id": "/subscriptions/0123456789/resourceGroups/vm-rg/providers/Microsoft.Compute/virtualMachines/vm1"
},
"vnetEncryptionSupported": false
}
}]