PostgreSQL UPDATE Join

This query shows how to use the PostgreSQL UPDATE join syntax to update data in a table based on values in another table. for example;

updating subscription_missions.giftbox_type with rewards.gift_box_type through mission_rewards table (tested on 300k records, crazy level fast)

  UPDATE
        subscription_missions sm
  SET
        giftbox_type = r.gift_box_type
  FROM
        mission_rewards mr,
        rewards r
  WHERE
        sm.giftbox_type IS NULL
        AND sm.id = mr.subscription_mission_id
        AND mr.reward_id = r.id;



1
Ali

Get our stories delivered

From us to your inbox weekly.