我计划实现一个使用 ltree 作为多级分类的数据库。但是,当我尝试获取路径 x 或 y 的条目时遇到了麻烦。
new_table
+-------+--------+---------+
| id | name | path |
----------------------------
| 1 | a | 001 |
| 2 | b | 002 |
| 3 | c | 001.001 |
| 4 | d | 002.001 |
| 5 | e | 003 |
----------------------------
根据下表,我想获得一个以 001 或 002 开头的 ID。但是我似乎无法获得正确的查询。
预期结果:1,2,3,4
这有效:select id from new_table where path <@ '001' or path <@ '002'
这不是(导致语法错误):select id from ingredient where ingredient_path <@ '001|002'
这让我感到困惑,因为 documentation声明使用 | (or) 符号是可以接受的。
我是 ltree 的新手,希望我能得到一个很容易理解的答案。
最佳答案
尝试:
select id from new_table where path ~ '001|002.*'
OR 不适用于 <@
运营商我认为,根据文档,
ltree <@ ltree
和|
可用于 lquery
相反
关于postgresql - 在 postgresql ltree 中使用多个参数搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44625459/