PostgreSQL ltree 查找给定路径的所有子节点(不使用表达式)

问题描述 投票:0回答:3

给定路径的唯一子节点(给定路径除外)

查询:

select path from tree where path <@ 'a.b.c';

结果:

预期结果:

a.b.c 以下所有节点(结果不需要 a.b.c)

sql postgresql select where-clause ltree
3个回答
2
投票

明确排除确切值怎么样?

select path 
from tree 
where path <@ 'a.b.c' and path <> 'a.b.c'

1
投票

或者,您可以使用:

select path 
from tree
where path ~ 'a.b.c.*{1}'

0
投票

或者,您可以使用:

select path from tree where path ~ 'a.b.c.*{1,}'

© www.soinside.com 2019 - 2024. All rights reserved.