Skip to content

Instantly share code, notes, and snippets.

@mkaranasou
Created January 19, 2020 17:01
Show Gist options
  • Save mkaranasou/630ed78bde11fd321645d3d6dc028015 to your computer and use it in GitHub Desktop.
Save mkaranasou/630ed78bde11fd321645d3d6dc028015 to your computer and use it in GitHub Desktop.
An example for generating data partitions by month - Postgres
-- 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