Created
May 24, 2018 15:58
-
-
Save saicitus/91555a29cccd59c10b48701a72dddebd to your computer and use it in GitHub Desktop.
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
BEGIN; | |
SET search_path TO 'public'; | |
CREATE SCHEMA temp_schema; | |
CREATE TABLE temp_schema.deviceid_rollup_daily (LIKE deviceid_rollup_daily INCLUDING ALL); | |
ALTER TABLE temp_schema.deviceid_rollup_daily ALTER COLUMN state SET DATA TYPE character varying(100); | |
SELECT create_distributed_table('temp_schema.deviceid_rollup_daily','state'); | |
INSERT INTO temp_schema.deviceid_rollup_daily SELECT * from deviceid_rollup_daily; | |
END; | |
-- Move the new table to the actual schema. | |
BEGIN; | |
SET search_path TO 'public'; | |
DROP TABLE deviceid_rollup_daily; | |
SELECT run_command_on_shards('temp_schema.deviceid_rollup_daily','ALTER TABLE %s SET SCHEMA public'); | |
SET citus.enable_ddl_propagation to off; | |
ALTER TABLE temp_schema.deviceid_rollup_daily SET SCHEMA public; | |
SET citus.enable_ddl_propagation to on; | |
DROP SCHEMA temp_schema; | |
END; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment