Last active
March 11, 2019 12:25
-
-
Save beanieboi/837e2a3a7ab5afd3835332cad5f3fd85 to your computer and use it in GitHub Desktop.
My Postgres Cheatsheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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$$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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