-- Copy labels from label_tmp staging table to labels table
-- Uses DISTINCT ON to ensure unique (labeler_actor_id, label, uri) combinations
INSERT INTO labels
SELECT DISTINCT on (labeler_actor_id, label, uri) *
FROM label_tmp
ON CONFLICT (labeler_actor_id, label, uri) DO UPDATE
    SET negated=EXCLUDED.negated,
        expires=EXCLUDED.expires,
        sig=EXCLUDED.sig,
        created_at=excluded.created_at
