So get the error:
SQL compilation error: The type of column 'COP' conflicts with the type of other columns in the UNPIVOT list.
If I use the data like to looks how you have it:
aka:
with exchange_rates(creation_date, jmd, isk, cop, usd, egp, pab) as (
select * from values
('2022-09-21 21:33:37.973'::timestamp_ntz, 153.3, 141.1, 4422.5, 1, 19.4, 1)
)
select *
from exchange_rates
unpivot(rate for currency in (jmd, isk, cop, usd, egp, pab) )
reading the error message, and slowing down, it's complaining of types
with exchange_rates(creation_date, jmd, isk, cop, usd, egp, pab) as (
select * from values
('2022-09-21 21:33:37.973'::timestamp_ntz, 153.3, 141.1, 4422.5, 1.0, 19.4, 1.0)
)
select *, system$typeof(jmd), system$typeof(cop), system$typeof(usd)
from exchange_rates
| CREATION_DATE |
JMD |
ISK |
COP |
USD |
EGP |
PAB |
SYSTEM$TYPEOF(JMD) |
SYSTEM$TYPEOF(COP) |
SYSTEM$TYPEOF(USD) |
| 2022-09-21 21:33:37.973 |
153.3 |
141.1 |
4,422.5 |
1 |
19.4 |
1 |
NUMBER(4,1)[SB2] |
NUMBER(5,1)[SB4] |
NUMBER(1,0)[SB1] |
and the 1 will default to a different type to the 141.1, to test, forcing it all to ::number(20,2)
with exchange_rates(creation_date, jmd, isk, cop, usd, egp, pab) as (
select * from values
('2022-09-21 21:33:37.973'::timestamp_ntz, 153.3::number(20,2), 141.1::number(20,2), 4422.5::number(20,2), 1.0::number(20,2), 19.4::number(20,2), 1.0::number(20,2))
)
select *
from exchange_rates
unpivot(rate for currency in (jmd, isk, cop, usd, egp, pab) )
works:
| CREATION_DATE |
CURRENCY |
RATE |
| 2022-09-21 21:33:37.973 |
JMD |
153.3 |
| 2022-09-21 21:33:37.973 |
ISK |
141.1 |
| 2022-09-21 21:33:37.973 |
COP |
4,422.5 |
| 2022-09-21 21:33:37.973 |
USD |
1 |
| 2022-09-21 21:33:37.973 |
EGP |
19.4 |
| 2022-09-21 21:33:37.973 |
PAB |
1 |