Created
October 13, 2023 03:59
-
-
Save unnoq/8a54e354d553a667afaf3ea6f470babb to your computer and use it in GitHub Desktop.
postgresql
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 $$ | |
DECLARE | |
counter integer := 1; | |
batch_size integer := 100; | |
BEGIN | |
WHILE counter <= 10000 LOOP | |
-- Use the counter to generate unique table names | |
EXECUTE 'CREATE TABLE IF NOT EXISTS "customer_histories_' || counter || '" PARTITION OF "customer_histories" FOR VALUES WITH (MODULUS 10000, REMAINDER ' || (counter - 1)::int || ');'; | |
counter := counter + 1; | |
-- WHILE NOT EXISTS (SELECT 1 FROM pg_indexes WHERE tablename = 'table_' || counter) LOOP | |
-- PERFORM pg_sleep(1); -- Wait for 1 second | |
-- END WHILE; | |
-- Commit every batch_size tables | |
IF counter % batch_size = 0 THEN | |
COMMIT; | |
END IF; | |
END LOOP; | |
-- Commit any remaining tables | |
COMMIT; | |
END $$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment