Have a table that has one column I want to duplicate, corresponding to several columns I want to stack on top of each other. I have a table like this (foo):
|col1 |col2 |col3 |
| 1 | A | F |
| 2 | B | G |
| 3 | C | H |
| 4 | D | I |
| 5 | E | J |
And I want to create a table like this (foo2):
|col_a |col_b |
| 1 | A |
| 2 | B |
| 3 | C |
| 4 | D |
| 5 | E |
| 1 | F |
| 2 | G |
| 3 | H |
| 4 | I |
| 5 | J |
This is as far as I got, this only stacks into one column:
DROP TABLE IF EXISTS foo2 CASCADE;
select col_a INTO foo2 from (
select col1 as col_a from foo
union all
select col2 as col_a from foo
union all
select col3 as col_a from foo
) as myview;