I want to split comma-separated String
inside SQLite database
Example: I have a Category
column in 1 of my table.
|Category
This variation of the answer provided by @user1461607 ensures that any CSV values that happen to be empty strings are preserved:
WITH RECURSIVE split(value, str) AS (
SELECT null, 'Auto,A,1234444' || ',' -- the string to be split
UNION ALL
SELECT
substr(str, 0, instr(str, ',')),
substr(str, instr(str, ',')+1)
FROM split WHERE str!=''
) SELECT value FROM split WHERE value is not NULL;
Assuming the JSON1 extension has been loaded, you could use json_group_array(value)
in the last line to convert
the CSV to a JSON array of strings.