I'm trying to get an UPSERT to work where I'm matching against fields (platform, company, sku (optional), title (optional)) instead of an id. I can't use the GUI because I can't check against NULL and a value at the same time. I wrote this query but am getting an error:
syntax error at or near "IF"
UPDATE product_ratings
SET
id = {{uuid.v4()}},
platform = {{platform_input.value}},
store = {{company_input.value}},
sku = {{sku_input.value}},
title = {{title_input.value}},
rating = {{rating.value}}
WHERE
platform = {{platform_input.value}}
AND store = {{company_input.value}}
AND (
(
{{!sku_input.value}}
AND sku ISNULL
)
OR sku = {{sku_input.value}}
)
AND (
(
{{!title_input.value}}
AND title ISNULL
)
OR title = {{title_input.value}}
)
IF @@ROWCOUNT = 0
INSERT INTO
product_ratings(
id,
platform,
store,
sku,
title,
rating
)
VALUES
({{uuid.v4()}}, {{platform_input.value}}, {{company_input.value}}, {{sku_input.value}}, {{title_input.value}}, {{rating_input.value}});