Du mangler bare en forbindende WHERE
klausul:
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;
Denne formular med NOT EXISTS
er sandsynligvis hurtigere, gør det samme:
UPDATE catalog_category c
SET leaf_category = true
WHERE NOT EXISTS (
SELECT FROM catalog_category c1
WHERE c1.parent_id = c.id
);
Relateret: