所以我想將我的 Postgres (v11) DB 磁區成幾個磁區。我已經弄清楚了如何通過使用我的一系列日期來做到這一點。
CREATE TABLE test(
some_id int,
some_date date,
some_value int,
) PARTITION BY RANGE (some_date);
但是我想根據日期的周數進行磁區。我嘗試了以下代碼但沒有成功:
CREATE TABLE test(
some_id int,
some_date date,
some_value int,
) PARTITION BY DATE_PART('week', some_date);
有人知道嗎?
uj5u.com熱心網友回復:
這仍然是范圍磁區,您只是使用單整數范圍。(串列磁區在這里也可以正常作業。)這里有一個顯示周磁區的縮寫示例 - IRL,您將有 52 個磁區覆寫第 1-52 周,而不是我在這里展示的 1、2、3-52。
testdb=# CREATE TABLE test( some_id int,
some_date date,
some_value int
) PARTITION BY range(DATE_PART('week', some_date));
CREATE TABLE
testdb=# create table test_week01 partition of test for values from (1) to (2);
CREATE TABLE
testdb=# create table test_week02 partition of test for values from (2) to (3);
CREATE TABLE
testdb=# create table test_week_rest partition of test for values from (3) to (MAXVALUE);
CREATE TABLE
testdb=# insert into test select 1, '2022-01-03', 2;
INSERT 0 1
testdb=# insert into test select 3, '2022-01-10', 4;
INSERT 0 1
testdb=# insert into test select 5, '2022-05-01', 6;
INSERT 0 1
testdb=# select tableoid::regclass, * from test;
tableoid | some_id | some_date | some_value
---------------- --------- ------------ ------------
test_week01 | 1 | 2022-01-03 | 2
test_week02 | 3 | 2022-01-10 | 4
test_week_rest | 5 | 2022-05-01 | 6
(3 rows)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/408988.html
標籤:
上一篇:添加連接并在列中搜索任何字串
