Je mist gewoon een verbindende WHERE
clausule:
UPDATE catalog_category c
SET leaf_category = true
FROM catalog_category c1
LEFT JOIN catalog_category c2 ON c1.id = c2.parent_id
WHERE c.id = c1.id
AND c2.parent_id IS NULL;
Dit formulier met NOT EXISTS
is waarschijnlijk sneller en doet hetzelfde:
UPDATE catalog_category c
SET leaf_category = true
WHERE NOT EXISTS (
SELECT FROM catalog_category c1
WHERE c1.parent_id = c.id
);
Gerelateerd: