这里我们使用基于哈希分区的数据库:
my_db = database(db_path, HASH, [SYMBOL, 10])
这行代码指定基于哈希分区,同时哈希值使用10个长度,这样既可以存放一般的股票代码,也可以存放比如期权这种比较长的代码
更多的分区表情况请参考:https://github.com/dolphindb/Tutorials_CN/blob/master/partitioned_in_memory_table.md
示例
db_path ="dfs://stock_check"
if (existsDatabase(db_path)){ // 判断数据库是否存在
dropDatabase(db_path) // 删除数据库
}
my_db = database(db_path, HASH, [SYMBOL, 10]) // 创建数据库
// 下面是一个示例表
randomN = 5
myTable = table(
"00001.sh" "00002.sh" "00003.sh" "00004.sh" "00005.sh" as stock_code,
randNormal(0,5,randomN) as x,
randNormal(1,5,randomN) as y,
randNormal(2,5,randomN) as z
)
myPartitionedTable = my_db.createPartitionedTable(myTable, `checkAddNewColTable, `stock_code)
myPartitionedTable.append!(myTable)
select * from myPartitionedTable
最后的效果: