有没有办法将列旋转成雪花行?

Is there a way to rotate column's to row in snowflake?

我有 table 单行如下,来自如下雪花查询

show warehouses like 'COMMON_WH';
select "name","state","type","size" FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))

name|state|type|size
COMMON_WH|SUSPENDED|STANDARD|Small

我想像下面这样旋转它。

name| COMMON_WH
state|SUSPENDED
type|STANDARD
size|Small

谢谢,

您可以使用 unpivot 来做到这一点。这是一个如何使用它的例子。请注意,它有点冗长,因为您需要在逆透视之前将所有原始 table 的数据类型转换为相同的数据类型(在本例中为 varchar)。

show warehouses like 'COMMON_WH';

select *
from (
    select
        "name"::varchar  as name,
        "state"::varchar as state,
        "type"::varchar  as type,
        "size"::varchar  as size
    FROM TABLE (RESULT_SCAN(LAST_QUERY_ID()))
) unpivot (col_val for col_name in (name, state, type, size))

这会产生:

COL_NAME COL_VAL
NAME COMMON_WH
STATE STARTED
TYPE STANDARD
SIZE X-Small