PostgreSQL:创建自增序列id,分区表,分区表子表
序列postgresql 创建 ID 自增 分区表
2023-09-27 14:26:28 时间
1)创建自增序列seq
CREATE SEQUENCE if not exists public.test_id_seq
INCREMENT 1
START 5
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
2)创建分区表主表
-- 创建表 根据ds分表(ds为yyyyMMdd格式)
create table test
(
id bigint NOT NULL DEFAULT nextval('test_id_seq'::regclass),
ip text,
name text,
create_time timestamp with time zone NOT NULL,
ds bigint
) PARTITION BY LIST (ds);
-- 创建注释
COMMENT ON TABLE test IS '分区表测试';
COMMENT ON COLUMN test.ip IS '访问ip';
COMMENT ON COLUMN test.name IS '名称';
COMMENT ON COLUMN test.create_time IS '创建时间';
3)创建分区表子表
-- 创建分区子表
-- create table %s_%s partition of %s for values in (%s)
create table test_20200924 partition of test for values in(20200924);
4)分区表数据插入
insert into test(ip,name,ds) values('1.1.1.1','good',20200924);
insert into test(ip,name,ds) values('1.1.1.1','good2',20200924);
insert into test(ip,name,ds) values('1.1.1.1','good3',20200924);
5)分区表查询
select name,to_char(create_time,'yyyymmddhh24mi') as period from test where ds in (20200921,20200922,20200923,20200924) and create_time <='2020-09-24 15:30:00.000' and create_time >= '2020-09-21 00:00:00.000' group by name,to_char(create_time,'yyyymmddhh24mi') order by name,period
相关文章
- Python 时间序列预测 | 详解 STL 算法和预测实践
- Python BiLSTM_CRF实现代码,电子病历命名实体识别和关系抽取,序列标注
- 时间序列-预测(Forcasting)-经典算法:Facebook Prophet【非常实用,适合预测趋势,但不太精准】
- 不通过删除重建方式,重置序列值的简单方法
- 数据分析-day05-pandas-dataFrame的时间序列、字符串转换成时间序列
- zoj1003-Max Sum (最大连续子序列之和)
- [LeetCode]Subsets II生成组合序列
- 基于粒子群改进的灰色时间序列预测,基于粒子群改进的灰色模型回归分析,
- MetricGraphics.js – 时间序列数据的可视化
- LeetCode·每日一题·792.匹配子序列的单词数·预处理
- 理解GL_TRIANGLE_STRIP等绘制三角形序列的三种方式
- 序列——堆排序-大根堆(堆大顶)
- 提取基因的特定外显子exon的碱基序列 | NCBI
- time series 时间序列 | fractional factorial design 部分要因试验设计
- PostgreSQL 空间、多维 序列 生成方法
- AcWing 3549. 最长非递减子序列
- AcWing 2816. 判断子序列
- Luogu2572 [SCOI2010]序列操作
- lightdb/postgresql中序列的使用以及oracle兼容计划
- 教你搭建多变量时间序列预测模型LSTM(附代码、数据集)
- PTA习题解析——判断DFS序列的合法性