Reputation: 21
Okay, so I have a table with ltree on a column called path. I want to select multiple paths, but I don't want to have a ton of OR statements. Is that possible or is this the best way to do it?
Paths:
Query:
SELECT content, path FROM threads WHERE path ~ 'schools.myschool.*' OR path ~ 'companies.about.*' OR path ~ 'testing.information.content.*
Upvotes: 2
Views: 2347
Reputation: 17712
You can join the regular expressions into one with the or-operator |
, and by separating the common suffix:
SELECT content, path FROM threads
WHERE path ~ '(schools.myschool|companies.about|testing.information.content).*'
Upvotes: 1
Reputation: 125454
select 'schools.myschool.*' ~ any(array[
'schools.myschool.*', 'companies.about.*', 'testing.information.content.*'
]);
?column?
----------
t
Upvotes: 2