Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
My Postgres Cheatsheet
DO LANGUAGE plpgsql $$
DECLARE counter INTEGER = 1;
DECLARE tick INTEGER = 1;
BEGIN
WHILE counter > 0 LOOP
UPDATE table
SET field = NULL
WHERE id IN (
SELECT id
FROM table
WHERE
field IS NOT NULL
LIMIT 100000
);
GET DIAGNOSTICS counter = ROW_COUNT;
raise notice 'Updated: %', counter;
raise notice 'Overall: %', tick*counter;
tick = tick + 1;
COMMIT;
END LOOP;
END$$;
ALTER TABLE table ALTER COLUMN id type uuid using id::uuid;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment