在Postgres中表示政策人口数据的最佳方式

时间:2016-05-15 14:16:41

标签: django database postgresql

我想构建一个Django服务,用户可以为某些人群定义一些策略。

政策样本:

default policy:
{
"field1":{
        "rule1":"somerule",
        "rule2":"somerule",
        "rule3":"somerule"
},
"filed2":{
    "rule1":"somerule",
    "rule2":"somerule",
    "moredata":[
        {"one":1,"two":2,"three":3},
        {"one":1,"two":2,"three":3}]
},
"filed3":{}
}

人口样本:

default population:
{
"field1":[{"1":"some1"},
        {"2":"some2"},
        {"3":"some3"}],
"filed2":[{"1":"some1"},
        {"2":"some2"},
        {"3":"some3"}],
"filed3":[{"1":"some1"},
        {"2":"some2"},
        {"3":"some3"}]
}

我想找到在PostgresDB中表示数据的最佳方法,我想到了两个db关系:

1:

population to policy:           field to population:

population  policyId            field   value           population
pop1        56                  field2  (lat,lon,rad)   pop1
pop2        999                 field3  (lat,lon,rad)   pop2
pop3        3                   field4  456             pop3

2:

population to policy:           expression to population:

population  policyId            expression                         population
pop1        56                  "filed1 AND filed4 OR filed2"      pop1
pop2        999                 "filed1 OR filed4 "                pop2
pop3        3

什么是更好的,有没有更好的方法来表示这种数据?

1 个答案:

答案 0 :(得分:0)

听起来非常适合JSONField