0

我有一棵这样的树:

               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 |
4

1 回答 1

0

通过使用运算符@>

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

官方ltree文件

于 2015-08-18T10:03:57.560 回答