Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何检查一个节点是否在 ltree 中重复(退出多个)?
像这样的东西:
'0.1.2.3.4.3.9' ==> True '0.1.2.3.4.5.9' ==> False
将其转换为字符串,将其拆分为表格并检查是否存在重复条目:
SELECT EXISTS (SELECT 1 FROM regexp_split_to_table( ltree2text('0.1.2.3.4.3.9'), '\.' ) AS labels(label) GROUP BY label HAVING count(*) > 1 );
根据您的评论,更好的选择可能是智能正则表达式:
SELECT ltree2text('0.1.2.3.4.5.9') ~ '(\m\d*\M).*\1';