Skip to content

Instantly share code, notes, and snippets.

@tjstebbing
Last active November 10, 2015 23:45
Show Gist options
  • Save tjstebbing/641577924fb32a7d6b4e to your computer and use it in GitHub Desktop.
Save tjstebbing/641577924fb32a7d6b4e to your computer and use it in GitHub Desktop.
-- Create 100 schemas shard_001 - shard_100
DO $shards$
BEGIN
FOR i IN 1..100 LOOP
DECLARE shardID TEXT := CONCAT('shard_', to_char(i, 'FM000'));
EXECUTE 'CREATE SCHEMA IF NOT EXISTS $1 AUTHORIZATION iflix;'
INTO c USING shardID;
END LOOP;
END $shards$;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment