Skip to content

Instantly share code, notes, and snippets.

@saicitus
Created May 24, 2018 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saicitus/91555a29cccd59c10b48701a72dddebd to your computer and use it in GitHub Desktop.
Save saicitus/91555a29cccd59c10b48701a72dddebd to your computer and use it in GitHub Desktop.
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