I’m looking for a way to do this in SingleStore:
I have a column with coma separated string that I need to split to different rows and the join to the table as a new column
sql server script:
SELECT id,
product_ids,
value new_col
FROM platform.manual_rule
CROSS APPLY STRING_SPLIT(product_ids, ',')
thank you,
I tried but I got this error massage (I also try with string split()) :
ERROR 1054 ER_BAD_FIELD_ERROR: Unknown column ‘value’ in ‘field list’
We also now support explicit LATERAL JOIN syntax that works for this and other kinds of queries. E.g.
singlestore> select * from r;
+------+------+
| id | s |
+------+------+
| 2 | c,d |
| 1 | a,b |
+------+------+
2 rows in set (0.03 sec)
singlestore> select * from r lateral join table(split(s,","));
+------+------+-----------+
| id | s | table_col |
+------+------+-----------+
| 2 | c,d | c |
| 2 | c,d | d |
| 1 | a,b | a |
| 1 | a,b | b |
+------+------+-----------+
You can also use a correlated subquery on the right of LATERAL. We still do an implicit lateral join when you used the TABLE function after a comma in the FROM list.
Correction: when you use JOIN TABLE(…) there is an implicit lateral operation. Explicit use of LATERAL with joins to TABLE is not allowed. E.g. this works:
create table r(id int, s text);
insert r values (1,"c,d"),(2,"a,b");
select * from r join table(split(s,","));
id,s,table_col
2,"a,b",a
2,"a,b",b
1,"c,d",c
1,"c,d",d
And, now we do support LATERAL join for other kinds of queries, as is fully described here: