SQLite Forum

Split an Extract column
Login
Because I find it challenging to keep track of deeply nested function calls I'll offer the following riff based on Keith's solution:

```
WITH the_table(id,this_column) AS (
    VALUES
        (1, '{1,1,20210206000704,,,,,1772285065,10,(10)4045420,100230,N,1}'),
        (2, '{1,1,20210126033937,,,,,1772285065,10,(317)5757554,100236 ,N,1}'),
        (3, '{1,1,20210202030039,,,,,1772285065,10,(325)4092770,100208 ,N,1}'),
        (4, '{1,1,20210202170400,,,,,1772285065,10,(377)4040420,100230 ,N,1}'),
        (5, '{1,1,20210203031334,,,,,1772285065,10,(45)4098070,100208, N,1}')
  ), front(id,a) AS (
    SELECT id, substr(this_column, instr(this_column, '(') + 1)
    FROM the_table
  ), back(id,b) AS (
    SELECT id, substr(a, 1, instr(a, ',') - 1)
    FROM front
  ), clean(id, c) AS (
    SELECT id, replace(b, ')', '')
    FROM back
  )
SELECT
    the_table.this_column,
    clean.c
FROM clean
INNER JOIN the_table
ON the_table.id = clean.id;
```

It requires SQLite to perform an extra scan, but it saves me from having to perform multiple scans over the SQL.