[MDEV-6574] split string Created: 2014-08-13  Updated: 2022-05-27  Due: 2014-08-27  Resolved: 2014-08-13

Status: Closed
Project: MariaDB Server
Component/s: None
Fix Version/s: N/A

Type: Task Priority: Minor
Reporter: james wang Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None


 Description   

nice to have a function split:

SELECT split("1,2,3,4,5", ',');

returns:
1
2
3
4
5



 Comments   
Comment by james wang [ 2014-08-13 ]

Does this incur a lot development time please?

Basically, I wish to convert a comma separated string, e.g. @str1="1,2,3,4,5", to an array @arr1 so I can use it in, e.g.

SELECT uid FROM table1 WHERE id IN (@arr1);

Thanks a lot in advance
James

Comment by Sergei Golubchik [ 2014-08-13 ]

Yes, it does.

But you can use FIND_IN_SET() function instead:

SELECT uid FROM table1 WHERE find_in_set(id, @arr1);

Comment by james wang [ 2014-08-13 ]

If it takes too much development time. please ignore this request.

Used find_in_set before, it was slow.

Of course, I can store @arr1 in my program and pass it to the second query as a parameter - very quick this way - but need to change code.

I was just wonder if there was a simpler way.

Comment by james wang [ 2014-08-13 ]

please close this ticket as I could not (even as the reporter).

Comment by Tom Miller [ 2022-05-27 ]

Maybe time to reopen this? I could really use this function.

SQL Server has a function STRING_SPLIT
Oracle regexp_substr
PostgreSQL string_to_array

Comment by Sergei Golubchik [ 2022-05-27 ]

STRING_SPLIT in SQL Server is a table-valued function, MariaDB doesn't have table-valued functions yet.
string_to_array returns an array, MariaDB doesn't have arrays yet either.
regexp_substr works, see https://mariadb.com/kb/en/regexp_substr/

Generated at Thu Feb 08 07:12:57 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.