好的,所以我在一个名为path的列上有一个带有ltree的表。我想选择多个路径,但我不想要大量的OR语句。这可能或者这是最好的方法吗?
路径:
查询:
SELECT content, path FROM threads WHERE path ~ 'schools.myschool.*' OR path ~ 'companies.about.*' OR path ~ 'testing.information.content.*
答案 0 :(得分:1)
select 'schools.myschool.*' ~ any(array[
'schools.myschool.*', 'companies.about.*', 'testing.information.content.*'
]);
?column?
----------
t
答案 1 :(得分:0)
您可以将正则表达式与or-operator |
合并为一个,并将公共后缀分开:
SELECT content, path FROM threads
WHERE path ~ '(schools.myschool|companies.about|testing.information.content).*'