Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use XPATH in MySQL select?

Tags:

sql

mysql

xpath

Say I have a table called "xml" that stores XML files in a single column "data". How would I write a MySQL query that run an XPath and return only rows matching that XPath?

like image 550
ripper234 Avatar asked Dec 08 '08 12:12

ripper234


1 Answers

SELECT * FROM xml
WHERE EXTRACTVALUE(data, '<xpath-expr>') != '';

You should note, however, that there are limitations to MySQL's support of XPath.

  • EXTRACTVALUE() returns only CDATA.
  • Not all XPath constructions are supported. Details under the heading "XPath limitations" on the doc page mentioned in abatishchev's answer.
like image 144
Bill Karwin Avatar answered Oct 29 '22 02:10

Bill Karwin