Does TiDB have a function to split a string into multiple lines?

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: tidb是否有分割字符串为多行的函数?

| username: Running

As shown in the data, you can parse “fc490ca45c00b1249bbe3554a4fdf6fb,f033ab37c30201f73f142449d037028d” into two separate pieces of data based on the comma.

| username: tidb菜鸟一只 | Original post link

CREATE TABLE USER (NAME VARCHAR(200));

INSERT INTO USER(NAME) VALUES(‘Zhang San, Li Si, Wang Wu’);

SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(a.name, ‘,’, b.help_topic_id + 1), ‘,’, -1) AS NAME
FROM USER a, (SELECT 0 help_topic_id UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3) b
WHERE b.help_topic_id < (LENGTH(a.name) - LENGTH(REPLACE(a.name, ‘,’, ‘’)) + 1);

| username: liuis | Original post link

The suggestion above is feasible, but I never understood why a database is needed for this task.

| username: dockerfile | Original post link

I also think that the database should try its best to retrieve rows or columns as quickly as possible, and the subsequent processing operations should be done by the program in memory.

| username: liuis | Original post link

Yes, I am very opposed to using database functions. Database resources are inherently limited, while program resources are now quite cheap. With k8s, resource utilization is very high, and scaling is convenient. I don’t understand why people like to perform sum, split, and time calculations in the database.

| username: xingzhenxiang | Original post link

Database computing can reduce logic on the development side.

| username: waeng | Original post link

It is recommended that the program handle this logic.

| username: Running | Original post link

You need to know in advance exactly how many there are inside, right?

| username: Running | Original post link

In a scenario where one person manages multiple campuses and such data is stored, now there is a need to count how many people are in each school.

| username: Running | Original post link

For statistical analysis scenarios, it is necessary to parse down to the data center.

| username: liuis | Original post link

The scenario you mentioned can also be achieved by the program for statistics.

| username: tidb菜鸟一只 | Original post link

No, the table you use to help with splitting can theoretically create an infinite number of rows, as long as the number of rows is greater than or equal to the number of your commas.

| username: Running | Original post link

Got it, I used find_in_set to handle it.

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.