[MDEV-26252] Function to count occurrences of a substring Created: 2021-07-27 Updated: 2021-07-27 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Minor |
| Reporter: | Federico Razzoli | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | functions | ||
| Description |
|
There is no trivial way to count the occurrences of a substring in a string. If you try searching Google, you'll see that many people asked how to that over the years. Generally, people suggest using expressions like this, which is terrible and painful:
Surprisingly, from a quick research, no DBMS seems to have a SUBSTR_COUNT() or equivalent function. Some have REGEXP_COUNT(), but I suggest implementing a simple function for simple cases instead. Some practical use cases for SUBSTR_COUNT() include counting the elements of a CSV and writing a CHECK constraint to validate strings in a particular format. |
| Comments |
| Comment by Federico Razzoli [ 2021-07-27 ] |
|
I opened this as a bug by mistake, it should be a task. I don't know how to convert it, though. |
| Comment by Anel Husakovic [ 2021-07-27 ] |
|
I did it. Thanks. |