pg分区表-按时间范围(range)
最后更新:2024-05-15 05:30:01
|
状态:未完成
|
相关数据库:
PostgreSQL
//根据时间范围分区 Table table = service.metadata().table("log_master", false); if(null != table){ service.ddl().drop(table); } MasterTable master = new MasterTable("log_master"); master.addColumn("ID", "INT"); master.addColumn("YMD", "DATE").setComment("日期"); master.addColumn("NAME", "VARCHAR(10)").setComment("姓名"); //设置主表分区依据的列 master.setPartition(Partition.TYPE.RANGE, "YMD"); service.ddl().create(master); PartitionTable log1 = new PartitionTable("LOG1"); log1.setMaster(master); //设置分区范围 log1.setPartition(new Partition(Partition.TYPE.RANGE).setFrom("2020-01-01").setTo("2020-01-31")); service.ddl().create(log1); PartitionTable log2 = new PartitionTable("LOG2"); log2.setMaster(master); //也可以不设置type共用主表的type log2.setPartition(new Partition().setFrom("2020-02-01").setTo("2020-05-31")); service.ddl().create(log2); DataRow log = new DataRow(); log.put("ID", 111); log.put("YMD", LocalDate.of(2020,3,1)); log.put("NAME","z"); service.insert("log_master", log); //从主表或相就的分区表中可以查到 service.querys("log_master"); service.querys("LOG2");