0

I have a question how to put number in each column. Right now, the data is looking like this.

Column A Column B
1 1, 2, 3, 4, 5, 6, 8, 10
2 4, 6, 7, 9, 11, 12

My goal is making this table look like this below.

Column A Column B
1 1
1 2
1 3
1 4

etc.

create table pp 
(
 id int,
    toppings int);
insert into pp
(id, toppings) 
values
(1,1),
(1,2),
(1,3),
(1,4),
(1,5),
(1,6),
(1,8),
(1,10),
(2,4),
(2,6),
(2,7),
(2,9),
(2,11),
(2,12);

I know this work but I'm looking for an easier way.

K.J.K
  • 11
  • 1

1 Answers1

1
select a, unnest(b) 
from pp;

unnest() transforms an array into a set of rows.

Here is the documentation.

And here is the demo.

Albina
  • 1,901
  • 3
  • 7
  • 19