当我试图在postgreSQL(pgAdmin)中执行这个查询select justify_interval('2000000 second');
时,它工作得很好,我得到的结果是:23天03:33:20,但是当我将它用于Pentaho报表设计器或Pentaho CDE时,我得到的结果是:00年00个月23天。。。。。,我的问题是:有任何方法可以得到相同的结果,比如Pentaho中的pgAdmin,我不想有0Screenshot from PEntaho Report Designer
最佳答案
可以在SQL查询中将值转换为字符串:
您只需在SQL中将值转换为文本或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
如果希望对结果值有更多的控制,可以使用
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
关于postgresql - pentaho CDE,来自PostgreSQL的报表设计器justify_interval查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38849167/