在配置单元cli中启用扩展表格式?

hwazgwia  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(246)

与此问题类似:是否有方法在prestodb cli中切换扩展表格式模式?。
有没有办法在配置单元中启用扩展表格式模式?在开始大查询作业之前,我想检查宽表中的一些记录。
从另一个问题复制示例:
展开表格格式之前:

select * from sometable;

 id | time  |       humanize_time             | value 
----+-------+---------------------------------+-------
  1 | 09:30 |  Early Morning - (9.30 am)      |   570
  2 | 11:30 |  Late Morning - (11.30 am)      |   690
  3 | 13:30 |  Early Afternoon - (1.30pm)     |   810
  4 | 15:30 |  Late Afternoon - (3.30 pm)     |   930
(4 rows)

之后:

select * from sometable;

-[ RECORD 1 ]-+---------------------------
id            | 1
time          | 09:30
humanize_time | Early Morning - (9.30 am)
value         | 570
-[ RECORD 2 ]-+---------------------------
id            | 2
time          | 11:30
humanize_time | Late Morning - (11.30 am)
value         | 690
-[ RECORD 3 ]-+---------------------------
id            | 3
time          | 13:30
humanize_time | Early Afternoon - (1.30pm)
value         | 810
-[ RECORD 4 ]-+---------------------------
id            | 4
time          | 15:30
humanize_time | Late Afternoon - (3.30 pm)
value         | 930
j7dteeu8

j7dteeu81#

你可以使用 CROSS JOIN , CASE 以及 UNION ALL .

select
  c.col,
  case c.col
    when 'id' then id
    when 'time' then time
    when 'humanize_time' then humanize_time
    when 'value' then value
  end as data
from sometable t
cross join
(
  select 'id' as col
  union all select 'time' as col
  union all select 'humanize_time' as col
  union all select 'value' as col
) c ORDER BY id;

相关问题