···11-with new_info as (
22- SELECT did, coalesce(following, 0) as following, coalesce(followers, 0) as followers
33- FROM actors
44- LEFT JOIN (SELECT did, count(*) AS following
55- FROM follows
66- GROUP BY 1) fi USING (did)
77- LEFT JOIN (SELECT subject as did, count(*) AS followers
88- FROM follows
99- GROUP BY 1) fe USING (did)
1010- where actors.did = any($1)
1111- )
1212- merge into follow_stats fs
1313-using new_info ni
1414-on ni.did = fs.did
1515-when matched then
1616- update
1717- set followers=ni.followers,
1818- following=ni.following
1919-when not matched then
2020- insert (did, followers, following)
2121- values (ni.did, ni.followers, ni.following);