mysql regex\u replace:如何在replace中使用regex组

xmd2e60i  于 2021-06-25  发布在  Mysql
关注(0)|答案(1)|浏览(434)

有一张table:

| id |      Name       |
|----------------------|
| 1  |test1 test1 test1|
| 2  |test2 test2 test2|

想要选择第一个regex组(使用第一个单词来简化),所以我的查询:

SELECT regexp_replace(name, "^([[:alnum:]]+)[[:space:]].*$","$1") FROM table;

结果:

|test1      |
|test1test2 |

那么结果是如何累积的呢?如何避免它,仍然能够使用正则表达式组?
upd:mysql版本:8.0.11,mysql社区服务器-gpl

acruukt9

acruukt91#

https://bugs.mysql.com/bug.php?id=90803 -5月21日:
已在8.0.12中修复。
regexp\u relace()来自一个结果集行的结果可能会结转到下一行,从而导致当前行中以前的结果的累积。

相关问题