This looks like strange behaviour, and I get the same on the MySQL command line as via db<>fiddle:

create table t(foo varchar(255));
insert into t (foo) values
('the quick brown fox'),
('jumped over the lazy dog');
select * from t;
| foo                      |
| :----------------------- |
| the quick brown fox      |
| jumped over the lazy dog |
select regexp_replace(foo, '[^a-z]+', '-') from t;
| regexp_replace(foo, '[^a-z]+', '-')         |
| :------------------------------------------ |
| the-quick-brown-fox                         |
| the-quick-brown-foxjumped-over-the-lazy-dog |

db<>fiddle here

I'd expect to see:

select REGEXP_REPLACE(foo, '[^a-z]+', '-') from t;
| REGEXP_REPLACE(foo, '[^a-z]+', '-') |
| :---------------------------------- |
| the-quick-brown-fox                 |
| jumped-over-the-lazy-dog            |

Am I doing something wrong or is this a MySQL bug?

有帮助吗?

解决方案

It's a known bug, 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.

许可以下: CC-BY-SA归因
不隶属于 dba.stackexchange
scroll top