partitioning - implement partitioning on PostgreSQL tables
问题描述
I'm implementing partition to PostgreSQL (version 12). I'll use the transaction_date (year) to create the partitions, one partition per year, trigger and function to save data on the right partition.
I'm applying the implementation Using Inheritance and how can I load the partitions for 2009, 2010, 2011, ...?
All the examples I found starts with an empty table.
Thanks
解决方案
我正在应用使用继承的实现
不要那样做。
使用 Postgres 12,您应该使用声明式分区,它也不需要使用触发器。
create table your_table
(
...,
transaction_date timestamp not null
)
partition by range (transaction_date);
create table your_table_p2018
partition of your_table
for values from ('2018-01-01') to ('2019-01-01');
create table your_table_p2019
partition of your_table
for values from ('2019-01-01') to ('2020-01-01');
create table your_table_p2020
partition of your_table
for values from ('2020-01-01') to ('2021-01-01');
插入your_table
将自动路由到适当的分区。
推荐阅读
- cassandra - 如何使用 SSL 选项和多节点选项从 exasol db 连接 cassandra db
- javascript - 带有变量和查找的 Jquery 选择器
- reactjs - 通过反应链接传递参数时,这里有点问题,我有“TypeError:无法读取未定义的属性'位置'”
- flutter - 由于上下文问题,无法从子类访问 bloc?
- javascript - 关于自定义 Blob 对象 URL
- javascript - 这是使用事件源的正确方法吗?
- html - 检查文本字段中是否输入了任何 html 标签或 javascript 代码
- r - 比较纵向数据集中连续行中的值
- ios - 如何为键盘扩展创建单元测试
- r - 使用 purrr::map() 更改和分配新变量名