这是代码:
UPDATE `xxx.xxx.gift_test_1`
SET PaymentLines = ARRAY(SELECT AS STRUCT * REPLACE('gift_card' AS PaymentType) FROM UNNEST(PaymentLines) WHERE PaymentMethod = 'gift_card')
WHERE true
这里的问题是我只需要在PaymentMethod =到'gift_card'的情况下将Payment类型更新为'gift_card',但是我的代码在执行后将EVERYTHING和PaymentMethod和PaymentType都更新为'gift_card'
更新1.0
UPDATE `xxx.xxx.gift_test_1`
SET PaymentLines = ARRAY(
SELECT AS STRUCT * REPLACE ('gift_card' AS PaymentType)
FROM UNNEST(PaymentLines) as pay
)
WHERE EXISTS (select 1 from unnest(PaymentLines) as pay WHERE pay.PaymentMethod = 'gift_card')
此代码将所有PaymentType更新为“ gift_card”,因此在这种情况下WHERE子句不起作用。
UPDATE 2.0
答案 0 :(得分:1)
应该是
UPDATE `xxx.xxx.gift_test_1`
SET PaymentLines = ARRAY(
SELECT AS STRUCT *
REPLACE(IF(PaymentMethod = 'gift_card', 'gift_card', PaymentType) AS PaymentType)
FROM UNNEST(PaymentLines) AS pay
)
WHERE true