2oppin
2oppin

Reputation: 2001

mysql regex_replace : how to use regex group in replacement

Have a table:

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

Want to select 1st regex group (used 1st word to simplify), so my query:

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

Result:

|test1      |
|test1test2 |

So how it comes that result is accumulated? And how to avoid it and still be able to use regex group?

UPD: Mysql version: 8.0.11, MySQL Community Server - GPL

Upvotes: 3

Views: 4120

Answers (1)

Rick James
Rick James

Reputation: 142518

https://bugs.mysql.com/bug.php?id=90803 - May 21:

Fixed in 8.0.12.

REGEXP_RELACE() results from one result set row could carry forward to the next row, resulting in accumulation of previous results in the current row.

Upvotes: 1

Related Questions