pentaho CDE,来自PostgreSQL的报告设计者justify_interval查询

时间:2016-08-09 11:11:52

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

当我尝试在postgreSQL(pgAdmin)中执行此查询select justify_interval('2000000 second');时,它完美地运行了我的结果: 23天03:33:20 ,但是当我将它用于Pentaho时报告设计师或Pentaho CDE,我得到了这样的结果: 00年00月23日..... ,我的问题是:有任何方法可以获得与Pentaho中的pgAdmin相同的结果,我不知道#39;我想拥有 0 Screenshot from PEntaho Report Designer

的文件

1 个答案:

答案 0 :(得分: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
    
  3. 输出: 23 day(s) 03:33:20