0

I have a tree like this:

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

In my database I have this records:

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

I want to search from a path, and get all the records for any node mathing that path, excluding what is not in the matched branch, like this:

| path                               |
|------------------------------------|
| Country                            |
| Country.State                      |
| Country.State.City1                |
| Country.State.City1.Neighborhood_1 |
Javier Seixas
  • 319
  • 3
  • 11

1 Answers1

0

By using the operator @>:

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

Official ltree Doc

Javier Seixas
  • 319
  • 3
  • 11