XPath Variables in MySQL 5.1.20
A few days ago, Alexander Barkov pushed some changes to the MySQL 5.1 tree that I’ve been waiting to see for some time — variable support for XPath functions used with ExtractValue() and UpdateXML(). (This was a fix for Bug #26518, BTW.) This will be available in MySQL 5.1.20 (or grab the MySQL 5.1 source from bkbits and build it yourself, if you just can’t wait).
Two slightly different notations are supported, depending on the context, and what sort of checking you want done on the values:
- If you don’t want or need type checking, prefix the variable name with
$@, like this:$@myvar. However, if you do this, and you make a typo, you’re on your own. - To make use of strict checking inside routines, leave off the
@sign, like this:$myvar.
This may not seem like a lot, but it greatly expands the usefulness of MySQL 5.1’s XML functions:
- You should now be able to import XML that uses practically any format into MySQL easily.
- This also makes it much easier to filter for specific rows/columns (or filter out unwated ones).
- You can easily do preprocessing with MySQL string functions like
CONCAT(),REPLACE(),TRIM(), etc.
I’ve not yet had time to play with this and come up with some good examples for the Manual, but I’m really looking forward to doing so. Keep an eye out for them in the XML Functions section of the Manual.



Comments(1)