MySQL xpath concatenation operator, how to add space?
This does what I expect:
mysql> select ExtractValue("<x><a>1</a><b>2</b></x>", "concat(/x/a, /x/b)");
+---------------------------------------------------------------+
| ExtractValue("<x><a>1</a><b>2</b></x>", "concat(/x/a, /x/b)") |
+---------------------------------------------------------------+
| 12 |
+---------------------------------------------------------------+
1 row in set (0.00 sec)
But why does this return "1" instead of "1 2"?
mysql> select ExtractValue("<x><a>1</a><b>2</b></x>", "concat(/x/a, ' ', /x/b)");
+--------------------------------------------------------------------+
| ExtractValue("<x><a>1</a><b>2</b></x>", "concat(/x/a, ' ', /x/b)") |
+--------------------------------------------------------------------+
| 1 |
+--------------------------------------------------------------------+
1 row in set (0.00 sec)
+4
2 answers
This is a verified error. The MySQL xpath concatenation operator only considers the first 2 parameters, when it must consider all parameters.
https://bugs.mysql.com/bug.php?id=71704
As a workaround, you can select individual values and pass them to a regular function concat:
select concat(ExtractValue("<x><a>1</a><b>2</b></x>", "/x/a"),' ',
ExtractValue("<x><a>1</a><b>2</b></x>", "/x/b"));
+4
Improvement detected:
mysql> select ExtractValue("<x><a>1</a><b>2</b></x>", "concat(/x/a, concat(' ', /x/b))");
+----------------------------------------------------------------------------+
| ExtractValue("<x><a>1</a><b>2</b></x>", "concat(/x/a, concat(' ', /x/b))") |
+----------------------------------------------------------------------------+
| 1 2 |
+----------------------------------------------------------------------------+
1 row in set (0.00 sec)
+3