Good evening! I have a simple database that stores xml data, in this case the author of the book and its text. The question is how to perform a search like LIKE, so as not to write the full content of the book or completely the author. At the moment I am doing this request:

SELECT * from storage where (xpath('//book/author/text()', documentcontent))[1]::text = '孝芯谢褋褌芯泄 袥械胁 袧懈泻芯谢邪械胁懈褔'::text; 
  • Xpath has a contains function. - Alexander Petrov

2 answers 2

There is contains, which is similar LIKE.

Used like this:

 .//span[contains(text(),"褌械泻褋褌 胁薪褍褌褉懈 褝谢械屑械薪褌邪")] 

    In general, I managed to find the answer, there were two of them.

    The first option pulls out only ONE value together with tags from the XML document stored in the table:

     SELECT unnest(xpath('//袟袛袝小鞋 校袣袗袟袗孝鞋 校袟袝袥/*[contains(text(),"孝校孝 袧袗袩袠小袗孝鞋 袠袥袠 校袣袗袟袗孝鞋 效袗小孝鞋 孝袝袣小孝袗, 袣袨孝袨袪蝎袡 啸袪袗袧袠孝小携 袙 XML")]', 孝校孝 校袣袗袟袗孝鞋 袠袦携 袩袨袥携::xml))::text AS XMLDATA FROM 孝校孝 校袣袗袟袗孝鞋 袠袦携 孝袗袘袥袠笑蝎; 

    The second option pulls ALL the value along with the tags from the XML document stored in the table:

     SELECT * from 孝校孝 校袣袗袟袗孝鞋 袠袦携 孝袗袘袥袠笑蝎 where (xpath('//袟袛袝小鞋 校袣袗袟袗孝鞋 校袟袝袥', 孝校孝 校袣袗袟袗孝鞋 袠袦携 袩袨袥携))[1]::text ILIKE '%孝校孝 校袣袗袟袗孝鞋 肖袪袗袟校 效袗小孝鞋挟 袠袥袠 笑袝袥袠袣袨袦'::text; 

    Hope to help you.