【问题标题】:Mathing all branch of a ltree in postgres在 postgres 中计算 ltree 的所有分支
【发布时间】:2015-08-18 10:03:57
【问题描述】:

我有一棵这样的树:

               Country
                  |
                State
              ____|____
             /         \
          City_1       City_2
      ______|______
     /             \
Neighborhood_1     Neighborhood_2

在我的数据库中,我有以下记录:

| path                               |
|------------------------------------|
| Country                            |
| Country.State                      |
| Country.State.City1                |
| Country.State.City2                |
| Country.State.City1.Neighborhood_1 |
| Country.State.City1.Neighborhood_2 |

我想从一个路径中搜索,并获取计算该路径的任何节点的所有记录,不包括不在匹配分支中的记录,如下所示:

| path                               |
|------------------------------------|
| Country                            |
| Country.State                      |
| Country.State.City1                |
| Country.State.City1.Neighborhood_1 |

【问题讨论】:

    标签: postgresql ltree


    【解决方案1】:

    通过使用运算符@>:

    select * from table where path @> Country.State.City1.Neighborhood_1
    

    Official ltree Doc

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-17
      • 2021-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-05
      相关资源
      最近更新 更多