Created
January 19, 2020 17:01
-
-
Save mkaranasou/630ed78bde11fd321645d3d6dc028015 to your computer and use it in GitHub Desktop.
An example for generating data partitions by month - Postgres
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
-- customer_transactions_y2020_m1-------------------------------------------------------- | |
CREATE TABLE IF NOT EXISTS customer_transactions_y2020_w1 ( | |
CHECK (transasction_date >= '2020-01-01 00:00:00' AND transasction_date <= '2020-01-31 23:59:59' ) | |
) INHERITS (customer_transactions); | |
-- customer_transactions_y2020_m2-------------------------------------------------------- | |
CREATE TABLE IF NOT EXISTS customer_transactions_y2020_w2 ( | |
CHECK (transasction_date >= '2020-02-01 00:00:00' AND transasction_date <= '2020-02-29 23:59:59' ) | |
) INHERITS (customer_transactions); | |
... | |
-- customer_transactions_y2020_m12-------------------------------------------------------- | |
CREATE TABLE IF NOT EXISTS customer_transactions_y2020_m12 ( | |
CHECK (transasction_date >= '2020-12-01 00:00:00' AND transasction_date <= '2020-12-31 23:59:59' ) | |
) INHERITS (customer_transactions); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment