# Line break or Single row to multiple rows

**URL:** https://community.dremio.com/t/line-break-or-single-row-to-multiple-rows/1923
**Category:** Uncategorized
**Created:** [September 25, 2018, 7:03am UTC](https://community.dremio.com/t/line-break-or-single-row-to-multiple-rows/1923 "2018-09-25T07:03:24Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Nhomeswaaronn](https://avatars.discourse-cdn.com/v4/letter/n/c77e96/32.png) [@Nhomeswaaronn](https://community.dremio.com/u/Nhomeswaaronn)
#### Post date: [September 25, 2018, 7:03am UTC](https://community.dremio.com/t/line-break-or-single-row-to-multiple-rows/1923/1 "2018-09-25T07:03:25Z")

</div>

Dear all,  
I need a sample select statement query for Line break(Single Cell value split in to Multiple Rows).  
Example,  
Input:  
ID Comment  
1 Test1 Test2 Test3

Output:  
1 Test1  
1 Test2  
1 Test3

Thanks,

---

<div class="post-metadata">

### Author: ![anthony](https://sea2.discourse-cdn.com/flex020/user_avatar/community.dremio.com/anthony/32/670_2.png) [@anthony](https://community.dremio.com/u/anthony)
#### Post date: [September 25, 2018, 12:17pm UTC](https://community.dremio.com/t/line-break-or-single-row-to-multiple-rows/1923/2 "2018-09-25T12:17:41Z")

</div>

The ability to pivot/unpivot is not currently supported today but is something we are considering for our roadmap.

---

<div class="post-metadata">

### Author: ![david.lee](https://avatars.discourse-cdn.com/v4/letter/d/ed655f/32.png) [@david.lee](https://community.dremio.com/u/david.lee)
#### Post date: [September 25, 2018, 10:22pm UTC](https://community.dremio.com/t/line-break-or-single-row-to-multiple-rows/1923/3 "2018-09-25T22:22:12Z")

</div>

This works, but there is also a bug…

```
SELECT Id, flatten(comment) AS comment
FROM (
  SELECT distinct Id, regexp_split(comment, '\Q \E', 'ALL', 10) AS comment
  FROM (
    select 1 as "Id", 'test1 test2 test3' as "comment"
  ) nested_0
) nested_0

```

The SQL using JDBC gives back correct results…

| Id | comment |
| --- | --- |
| 1 | test1 |
| 1 | test2 |
| 1 | test3 |

For some reason the Dremio UI gives back

| Id | comment |
| --- | --- |
| 1 | test1 |
| 1 | test2 |
| 1 | test3 |
| 1 | test1 |
| 1 | test2 |
| 1 | test3 |
| 1 | test1 |
| 1 | test2 |
| 1 | test3 |
| 1 | test1 |
| 1 | test2 |
| 1 | test3 |
| 1 | test1 |
| 1 | test2 |
| 1 | test3 |
| 1 | test1 |
| 1 | test2 |
| 1 | test3 |

---

<div class="post-metadata">

### Author: ![david.lee](https://avatars.discourse-cdn.com/v4/letter/d/ed655f/32.png) [@david.lee](https://community.dremio.com/u/david.lee)
#### Post date: [September 25, 2018, 10:30pm UTC](https://community.dremio.com/t/line-break-or-single-row-to-multiple-rows/1923/4 "2018-09-25T22:30:26Z")

</div>

The Dremio UI fixes itself (3 rows showing) if you change Preview to Run and if you switch back to Preview it stays at 3 rows… Bug with initial Preview

---

<div class="post-metadata">

### Author: ![Nhomeswaaronn](https://avatars.discourse-cdn.com/v4/letter/n/c77e96/32.png) [@Nhomeswaaronn](https://community.dremio.com/u/Nhomeswaaronn)
#### Post date: [September 26, 2018, 6:01am UTC](https://community.dremio.com/t/line-break-or-single-row-to-multiple-rows/1923/5 "2018-09-26T06:01:11Z")

</div>

Hi David,

By Using Flatten it is Splitting in all Double quotes, my requirement is to split at every ANL

Sample:  
["\nANL;1;DSC-C121;1;1;V",“CAP”,“DSC-C121”,"\>",“0.05V;;FAIL(+/-);0.000000e+00;0.000000e+00;0.000000e+00;;;1\r\nANL;1;”]

here i need  
ANL;1;DSC-C121;1;1;V",“CAP”,“DSC-C121”,"\>","0.05V;;FAIL(+/-);0.000000e+00;0.000000e+00;0.000000e+00;;;1 as First line

ANL as Second line

Thanks.

---

<div class="post-metadata">

### Author: ![david.lee](https://avatars.discourse-cdn.com/v4/letter/d/ed655f/32.png) [@david.lee](https://community.dremio.com/u/david.lee)
#### Post date: [September 26, 2018, 4:41pm UTC](https://community.dremio.com/t/line-break-or-single-row-to-multiple-rows/1923/6 "2018-09-26T16:41:46Z")

</div>

Just change the REGEX to split a string into array by “\n” instead of " "

SELECT flatten(raw\_column) AS raw\_column  
FROM (  
SELECT regexp\_split(raw\_column, ‘\Q\n\E’, ‘ALL’, 10) AS raw\_column  
FROM (  
select ‘\nANL;1;DSC-C121;1;1;V",“CAP”,“DSC-C121”,"\>",“0.05V;;FAIL(+/-);0.000000e+00;0.000000e+00;0.000000e+00;;;1\r\nANL;1;”’ as “raw\_column”  
) nested\_0  
) nested\_0

```
raw_column

ANL;1;DSC-C121;1;1;V","CAP","DSC-C121",">","0.05V;;FAIL(+/-);0.000000e+00;0.000000e+00;0.000000e+00;;;1\r
ANL;1;"
```

---

<div class="post-metadata">

### Author: ![Nhomeswaaronn](https://avatars.discourse-cdn.com/v4/letter/n/c77e96/32.png) [@Nhomeswaaronn](https://community.dremio.com/u/Nhomeswaaronn)
#### Post date: [October 3, 2018, 10:16am UTC](https://community.dremio.com/t/line-break-or-single-row-to-multiple-rows/1923/7 "2018-10-03T10:16:41Z")

</div>

Thanks David,

yes it is working Fine.

i did like this  
SELECT row\_key, flatten(regexp\_split(ANL, ‘\Q  
\E’, ‘ALL’, 100000)) AS ANL
