How do I upsert using raw SQL?

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}});

Hi @matthoffman :wave: thanks for reaching out with this!

I just wanted to see if you were still facing this issue? If so, would you be able to let us know which resource type (e.g. MySQL, PostgreSQL, etc.) you're using? We'll be happy to a further look!

Hi @luke-phillippi yeah I'm still facing this. I'm using a postgresql db.