【问题标题】:pentaho CDE, report designer justify_interval query from PostgreSQLpentaho CDE,来自 PostgreSQL 的报表设计器 justify_interval 查询
【发布时间】:2016-08-09 11:11:52
【问题描述】:

当我尝试在 postgreSQL (pgAdmin) 中执行此查询 select justify_interval('2000000 second'); 时,它工作得很好,我得到了这个结果:23 days 03:33:20,但是当我将它用于 Pentaho Report 设计器时或 Pentaho CDE,我得到了这个结果:00 年 00 个月 23 天.....,我的问题是:有任何方法可以在 Pentaho 中获得与 pgAdmin 相同的结果,我没有想要向 0 Screenshot from PEntaho Report Designer

提交文件

【问题讨论】:

    标签: postgresql reporting pentaho postgresql-9.4 pentaho-cde


    【解决方案1】:

    您可以在 SQL 查询中将您的值转换为字符串:

    1. 您可以在 SQL 中简单地将值转换为 text 或 varchar:

      select justify_interval('2000000 second')::text as justify_interval;
      

      select cast(justify_interval('2000000 second') AS text) as justify_interval
      

      输出: 23 days 03:33:20

    2. 如果您想对结果值进行更多控制,可以使用date_part()extract() SQL 函数提取区间的不同部分。然后,您将能够根据需要对这些部分进行格式化,并以所需语言附加文本:

      -- common table expression just to avoid writing justify_interval('2000000 second')
      -- in every date_part entry:
      WITH interval_cte(interval_column) AS (
          VALUES(justify_interval('2000000 second'))
      )
      SELECT
          -- trim to remove trailing space, if seconds are null
          -- nullif(*, 0) will make it null if the date part is 0
          -- in this case the subsequent concatenation with ' *(s)' will result in null too
          -- finally(*,''), coalesce will replace null with empty string, so that 
          -- subsequent concatenations will not dissappear:
          COALESCE(NULLIF(date_part('year', interval_column), 0) || ' year(s) ', '') 
          || COALESCE(NULLIF(date_part('month', interval_column), 0) || ' month(s) ', '') 
          || COALESCE(NULLIF(date_part('day', interval_column), 0) || ' day(s) ', '') 
          -- FM prefix will suppress leading whitespace,
          -- 00 will output leading zeros if number has less then two digits
          || to_char(date_part('hour', interval_column), 'FM00') || ':'
          || to_char(date_part('minute', interval_column), 'FM00') || ':'
          || to_char(date_part('second', interval_column), 'FM00') AS justofy_interval
      FROM interval_cte
      

    输出: 23 day(s) 03:33:20

    【讨论】:

    • 感谢您提供这个有用的答案,效果很好
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-02
    • 2014-08-14
    • 1970-01-01
    相关资源
    最近更新 更多