Skip to content

Instantly share code, notes, and snippets.

@hadihammurabi
Last active September 19, 2019 04:53
Show Gist options
  • Save hadihammurabi/07186db8df0a718df4d35a078f4344a6 to your computer and use it in GitHub Desktop.
Save hadihammurabi/07186db8df0a718df4d35a078f4344a6 to your computer and use it in GitHub Desktop.
PostgreSQL Sharding with Declarative Partition Example
CREATE TYPE jeniskelamin AS ENUM('l', 'p');
CREATE TABLE users (
username VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
jk jeniskelamin NOT NULL
) PARTITION BY LIST(jk);
CREATE TABLE users_l PARTITION OF users FOR VALUES IN('l');
CREATE TABLE users_p PARTITION OF users FOR VALUES IN('p');
INSERT INTO users VALUES ('hadihammurabi', '123123aaa', 'l');
SELECT * FROM users;
SELECT * FROM users_l;
SELECT * FROM users_p;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment