1-- Copy labels from label_tmp staging table to labels table
2-- Uses DISTINCT ON to ensure unique (labeler_actor_id, label, uri) combinations
3INSERT INTO labels
4SELECT DISTINCT on (labeler_actor_id, label, uri) *
5FROM label_tmp
6ON CONFLICT (labeler_actor_id, label, uri) DO UPDATE
7 SET negated=EXCLUDED.negated,
8 expires=EXCLUDED.expires,
9 sig=EXCLUDED.sig,
10 created_at=excluded.created_at