Why does REGEXP_REPLACE concatenate with a previous result? This looks like strange behaviour, and I get the same on the MySQL command line as via db&lt;>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&lt;>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.