I have a table with about 20 columns. It currently holds 8 million rows of data.
I need to update one NULL column for all 8 million rows, it is a GUID column and a FK for another table column.
Currently, I am running simple update query in a loop. But it is taking way too long.
DO $$
BEGIN
FOR counter IN 1..1000 LOOP
UPDATE "Shops"
SET "Country" = '410006e1-ca4e-4502-a9ec-e54d922d2c00'
FROM (SELECT "Id"
FROM "Shops"
WHERE "Country" IS NULL LIMIT 1000)
AS "part"
WHERE "Shops"."Id" = "part"."Id";
COMMIT;
RAISE NOTICE 'Counter: %', counter;
END LOOP;
END; $$
explain (analyze, buffers)on your query to see why it is so slow.