{"id":502,"date":"2026-02-06T16:56:48","date_gmt":"2026-02-06T16:56:48","guid":{"rendered":"http:\/\/77interactive.com\/?p=502"},"modified":"2026-02-06T16:57:33","modified_gmt":"2026-02-06T16:57:33","slug":"partition","status":"publish","type":"post","link":"http:\/\/77interactive.com\/?p=502","title":{"rendered":"Partition"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>DROP TABLE IF EXISTS sales CASCADE;\n\n-- Create parent table with partitioning\nCREATE TABLE sales (\n    id bigint NOT NULL GENERATED ALWAYS AS IDENTITY,\n    sale_date DATE NOT NULL,\n    amount NUMERIC(10, 2) NOT NULL,\n    customer TEXT NOT NULL,\n    PRIMARY KEY (id, sale_date)\n) PARTITION BY RANGE (sale_date);\n\n-- create some indexes\n\n-- Create default partition\nCreate table sales_default partition of sales default;\n\n-- January 2024 partition\ncreate table sales_2024_01 partition of sales for values from ('2024-01-01') to ('2024-02-01');\ncreate table sales_2024_02 partition of sales for values from ('2024-02-01') to ('2024-03-01');\ncreate table sales_2024_03 partition of sales for values from ('2024-03-01') to ('2024-04-01');\ncreate table sales_2024_04 partition of sales for values from ('2024-04-01') to ('2024-05-01');\ncreate table sales_2024_05 partition of sales for values from ('2024-05-01') to ('2024-06-01');\ncreate table sales_2024_06 partition of sales for values from ('2024-06-01') to ('2024-07-01');\ncreate table sales_2024_07 partition of sales for values from ('2024-07-01') to ('2024-08-01');\ncreate table sales_2024_08 partition of sales for values from ('2024-08-01') to ('2024-09-01');\ncreate table sales_2024_09 partition of sales for values from ('2024-09-01') to ('2024-10-01');\ncreate table sales_2024_10 partition of sales for values from ('2024-10-01') to ('2024-11-01');\ncreate table sales_2024_11 partition of sales for values from ('2024-11-01') to ('2024-12-01');\ncreate table sales_2024_12 partition of sales for values from ('2024-12-01') to ('2025-01-01');\n\n-- January 2023 partition\ncreate table sales_2023_01 partition of sales for values from ('2023-01-01') to ('2023-02-01');\ncreate table sales_2023_02 partition of sales for values from ('2023-02-01') to ('2023-03-01');\ncreate table sales_2023_03 partition of sales for values from ('2023-03-01') to ('2023-04-01');\ncreate table sales_2023_04 partition of sales for values from ('2023-04-01') to ('2023-05-01');\ncreate table sales_2023_05 partition of sales for values from ('2023-05-01') to ('2023-06-01');\ncreate table sales_2023_06 partition of sales for values from ('2023-06-01') to ('2023-07-01');\ncreate table sales_2023_07 partition of sales for values from ('2023-07-01') to ('2023-08-01');\ncreate table sales_2023_08 partition of sales for values from ('2023-08-01') to ('2023-09-01');\ncreate table sales_2023_09 partition of sales for values from ('2023-09-01') to ('2023-10-01');\ncreate table sales_2023_10 partition of sales for values from ('2023-10-01') to ('2023-11-01');\ncreate table sales_2023_11 partition of sales for values from ('2023-11-01') to ('2023-12-01');\ncreate table sales_2023_12 partition of sales for values from ('2023-12-01') to ('2024-01-01');\n\n-- January 2025 partition\ncreate table sales_2025_01 partition of sales for values from ('2025-01-01') to ('2025-02-01');\ncreate table sales_2025_02 partition of sales for values from ('2025-02-01') to ('2025-03-01');\ncreate table sales_2025_03 partition of sales for values from ('2025-03-01') to ('2025-04-01');\ncreate table sales_2025_04 partition of sales for values from ('2025-04-01') to ('2025-05-01');\ncreate table sales_2025_05 partition of sales for values from ('2025-05-01') to ('2025-06-01');\ncreate table sales_2025_06 partition of sales for values from ('2025-06-01') to ('2025-07-01');\ncreate table sales_2025_07 partition of sales for values from ('2025-07-01') to ('2025-08-01');\ncreate table sales_2025_08 partition of sales for values from ('2025-08-01') to ('2025-09-01');\ncreate table sales_2025_09 partition of sales for values from ('2025-09-01') to ('2025-10-01');\ncreate table sales_2025_10 partition of sales for values from ('2025-10-01') to ('2025-11-01');\ncreate table sales_2025_11 partition of sales for values from ('2025-11-01') to ('2025-12-01');\ncreate table sales_2025_12 partition of sales for values from ('2025-12-01') to ('2026-01-01');\n\n-- 2026 partitions\nCREATE TABLE sales_2026_01 PARTITION OF sales FOR VALUES FROM ('2026-01-01') TO ('2026-02-01');\nCREATE TABLE sales_2026_02 PARTITION OF sales FOR VALUES FROM ('2026-02-01') TO ('2026-03-01');\nCREATE TABLE sales_2026_03 PARTITION OF sales FOR VALUES FROM ('2026-03-01') TO ('2026-04-01');\nCREATE TABLE sales_2026_04 PARTITION OF sales FOR VALUES FROM ('2026-04-01') TO ('2026-05-01');\nCREATE TABLE sales_2026_05 PARTITION OF sales FOR VALUES FROM ('2026-05-01') TO ('2026-06-01');\nCREATE TABLE sales_2026_06 PARTITION OF sales FOR VALUES FROM ('2026-06-01') TO ('2026-07-01');\nCREATE TABLE sales_2026_07 PARTITION OF sales FOR VALUES FROM ('2026-07-01') TO ('2026-08-01');\nCREATE TABLE sales_2026_08 PARTITION OF sales FOR VALUES FROM ('2026-08-01') TO ('2026-09-01');\nCREATE TABLE sales_2026_09 PARTITION OF sales FOR VALUES FROM ('2026-09-01') TO ('2026-10-01');\nCREATE TABLE sales_2026_10 PARTITION OF sales FOR VALUES FROM ('2026-10-01') TO ('2026-11-01');\nCREATE TABLE sales_2026_11 PARTITION OF sales FOR VALUES FROM ('2026-11-01') TO ('2026-12-01');\nCREATE TABLE sales_2026_12 PARTITION OF sales FOR VALUES FROM ('2026-12-01') TO ('2027-01-01');\n\n-- 2027 partitions\nCREATE TABLE sales_2027_01 PARTITION OF sales FOR VALUES FROM ('2027-01-01') TO ('2027-02-01');\nCREATE TABLE sales_2027_02 PARTITION OF sales FOR VALUES FROM ('2027-02-01') TO ('2027-03-01');\nCREATE TABLE sales_2027_03 PARTITION OF sales FOR VALUES FROM ('2027-03-01') TO ('2027-04-01');\nCREATE TABLE sales_2027_04 PARTITION OF sales FOR VALUES FROM ('2027-04-01') TO ('2027-05-01');\nCREATE TABLE sales_2027_05 PARTITION OF sales FOR VALUES FROM ('2027-05-01') TO ('2027-06-01');\nCREATE TABLE sales_2027_06 PARTITION OF sales FOR VALUES FROM ('2027-06-01') TO ('2027-07-01');\nCREATE TABLE sales_2027_07 PARTITION OF sales FOR VALUES FROM ('2027-07-01') TO ('2027-08-01');\nCREATE TABLE sales_2027_08 PARTITION OF sales FOR VALUES FROM ('2027-08-01') TO ('2027-09-01');\nCREATE TABLE sales_2027_09 PARTITION OF sales FOR VALUES FROM ('2027-09-01') TO ('2027-10-01');\nCREATE TABLE sales_2027_10 PARTITION OF sales FOR VALUES FROM ('2027-10-01') TO ('2027-11-01');\nCREATE TABLE sales_2027_11 PARTITION OF sales FOR VALUES FROM ('2027-11-01') TO ('2027-12-01');\nCREATE TABLE sales_2027_12 PARTITION OF sales FOR VALUES FROM ('2027-12-01') TO ('2028-01-01');\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>insert into sales(sale_date, amount, customer)\nselect\n\n        date '2023-01-01' + (random() * 364)::int\n    ,\n    round((2.99 + random() * (1870.00 - 2.99))::numeric, 2),\n    (array&#91;\n        'Beauty','Clothing','Health','Industrial','Kids','Garden','Toys','Tools','Computers','Electronics',\n        'Jewelry','Books','Movies','Grocery','Automotive','Outdoors','Music','Home','Sports','Games','Baby','Shoes'\n    ])&#91;floor(random()*22 + 1)]\nfrom generate_series(1,50000);\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE sales_archive (LIKE sales INCLUDING ALL) \nPARTITION BY RANGE (sale_date);\n\nALTER TABLE sales DETACH PARTITION sales_2023_01;\n\nALTER TABLE sales_archive ATTACH PARTITION sales_2023_01 \nFOR VALUES FROM ('2023-01-01') TO ('2023-02-01');<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":233,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[17,18],"class_list":["post-502","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-postgresql","tag-postgres","tag-postgresql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Partition - 77 Interactive<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/77interactive.com\/?p=502\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Partition - 77 Interactive\" \/>\n<meta property=\"og:url\" content=\"http:\/\/77interactive.com\/?p=502\" \/>\n<meta property=\"og:site_name\" content=\"77 Interactive\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-06T16:56:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-02-06T16:57:33+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/77interactive.com\/wp-content\/uploads\/2023\/07\/minimal-violet-galaxy-elephant-logo-on-lilac-background-452a77db.png\" \/>\n\t<meta property=\"og:image:width\" content=\"512\" \/>\n\t<meta property=\"og:image:height\" content=\"512\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Rudy\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rudy\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/77interactive.com\/?p=502#article\",\"isPartOf\":{\"@id\":\"http:\/\/77interactive.com\/?p=502\"},\"author\":{\"name\":\"Rudy\",\"@id\":\"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9\"},\"headline\":\"Partition\",\"datePublished\":\"2026-02-06T16:56:48+00:00\",\"dateModified\":\"2026-02-06T16:57:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/77interactive.com\/?p=502\"},\"wordCount\":1,\"image\":{\"@id\":\"http:\/\/77interactive.com\/?p=502#primaryimage\"},\"thumbnailUrl\":\"http:\/\/77interactive.com\/wp-content\/uploads\/2023\/07\/minimal-violet-galaxy-elephant-logo-on-lilac-background-452a77db.png\",\"keywords\":[\"postgres\",\"postgresql\"],\"articleSection\":[\"PostgreSQL\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/77interactive.com\/?p=502\",\"url\":\"http:\/\/77interactive.com\/?p=502\",\"name\":\"Partition - 77 Interactive\",\"isPartOf\":{\"@id\":\"http:\/\/77interactive.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/77interactive.com\/?p=502#primaryimage\"},\"image\":{\"@id\":\"http:\/\/77interactive.com\/?p=502#primaryimage\"},\"thumbnailUrl\":\"http:\/\/77interactive.com\/wp-content\/uploads\/2023\/07\/minimal-violet-galaxy-elephant-logo-on-lilac-background-452a77db.png\",\"datePublished\":\"2026-02-06T16:56:48+00:00\",\"dateModified\":\"2026-02-06T16:57:33+00:00\",\"author\":{\"@id\":\"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9\"},\"breadcrumb\":{\"@id\":\"http:\/\/77interactive.com\/?p=502#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/77interactive.com\/?p=502\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/77interactive.com\/?p=502#primaryimage\",\"url\":\"http:\/\/77interactive.com\/wp-content\/uploads\/2023\/07\/minimal-violet-galaxy-elephant-logo-on-lilac-background-452a77db.png\",\"contentUrl\":\"http:\/\/77interactive.com\/wp-content\/uploads\/2023\/07\/minimal-violet-galaxy-elephant-logo-on-lilac-background-452a77db.png\",\"width\":512,\"height\":512},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/77interactive.com\/?p=502#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/77interactive.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Partition\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/77interactive.com\/#website\",\"url\":\"http:\/\/77interactive.com\/\",\"name\":\"77 Interactive\",\"description\":\"Rudy&#039;s Code snippets\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/77interactive.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9\",\"name\":\"Rudy\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/77interactive.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e336b9aecd39b40691ff8ccfcd68506415072dbe8caffc0485b94a1bc22b774d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e336b9aecd39b40691ff8ccfcd68506415072dbe8caffc0485b94a1bc22b774d?s=96&d=mm&r=g\",\"caption\":\"Rudy\"},\"url\":\"http:\/\/77interactive.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Partition - 77 Interactive","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/77interactive.com\/?p=502","og_locale":"en_US","og_type":"article","og_title":"Partition - 77 Interactive","og_url":"http:\/\/77interactive.com\/?p=502","og_site_name":"77 Interactive","article_published_time":"2026-02-06T16:56:48+00:00","article_modified_time":"2026-02-06T16:57:33+00:00","og_image":[{"width":512,"height":512,"url":"http:\/\/77interactive.com\/wp-content\/uploads\/2023\/07\/minimal-violet-galaxy-elephant-logo-on-lilac-background-452a77db.png","type":"image\/png"}],"author":"Rudy","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Rudy","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/77interactive.com\/?p=502#article","isPartOf":{"@id":"http:\/\/77interactive.com\/?p=502"},"author":{"name":"Rudy","@id":"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9"},"headline":"Partition","datePublished":"2026-02-06T16:56:48+00:00","dateModified":"2026-02-06T16:57:33+00:00","mainEntityOfPage":{"@id":"http:\/\/77interactive.com\/?p=502"},"wordCount":1,"image":{"@id":"http:\/\/77interactive.com\/?p=502#primaryimage"},"thumbnailUrl":"http:\/\/77interactive.com\/wp-content\/uploads\/2023\/07\/minimal-violet-galaxy-elephant-logo-on-lilac-background-452a77db.png","keywords":["postgres","postgresql"],"articleSection":["PostgreSQL"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"http:\/\/77interactive.com\/?p=502","url":"http:\/\/77interactive.com\/?p=502","name":"Partition - 77 Interactive","isPartOf":{"@id":"http:\/\/77interactive.com\/#website"},"primaryImageOfPage":{"@id":"http:\/\/77interactive.com\/?p=502#primaryimage"},"image":{"@id":"http:\/\/77interactive.com\/?p=502#primaryimage"},"thumbnailUrl":"http:\/\/77interactive.com\/wp-content\/uploads\/2023\/07\/minimal-violet-galaxy-elephant-logo-on-lilac-background-452a77db.png","datePublished":"2026-02-06T16:56:48+00:00","dateModified":"2026-02-06T16:57:33+00:00","author":{"@id":"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9"},"breadcrumb":{"@id":"http:\/\/77interactive.com\/?p=502#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/77interactive.com\/?p=502"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/77interactive.com\/?p=502#primaryimage","url":"http:\/\/77interactive.com\/wp-content\/uploads\/2023\/07\/minimal-violet-galaxy-elephant-logo-on-lilac-background-452a77db.png","contentUrl":"http:\/\/77interactive.com\/wp-content\/uploads\/2023\/07\/minimal-violet-galaxy-elephant-logo-on-lilac-background-452a77db.png","width":512,"height":512},{"@type":"BreadcrumbList","@id":"http:\/\/77interactive.com\/?p=502#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/77interactive.com\/"},{"@type":"ListItem","position":2,"name":"Partition"}]},{"@type":"WebSite","@id":"http:\/\/77interactive.com\/#website","url":"http:\/\/77interactive.com\/","name":"77 Interactive","description":"Rudy&#039;s Code snippets","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/77interactive.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9","name":"Rudy","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/77interactive.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e336b9aecd39b40691ff8ccfcd68506415072dbe8caffc0485b94a1bc22b774d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e336b9aecd39b40691ff8ccfcd68506415072dbe8caffc0485b94a1bc22b774d?s=96&d=mm&r=g","caption":"Rudy"},"url":"http:\/\/77interactive.com\/?author=1"}]}},"_links":{"self":[{"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/posts\/502","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/77interactive.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=502"}],"version-history":[{"count":1,"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/posts\/502\/revisions"}],"predecessor-version":[{"id":503,"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/posts\/502\/revisions\/503"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/media\/233"}],"wp:attachment":[{"href":"http:\/\/77interactive.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=502"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/77interactive.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=502"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/77interactive.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=502"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}