pentaho CDE,报表设计器 justify_interval 来自 PostgreSQL 的查询
pentaho CDE, report designer justify_interval query from PostgreSQL
当我尝试在 postgreSQL (pgAdmin) 中执行此查询 select justify_interval('2000000 second');
时,它工作得很好,我得到了这个结果:23 天 03:33:20,但是当我将它用于 Pentaho Report designer 或 Pentaho CDE,我得到了这个结果:00 years 00 months 23 days .....,我的问题是:有什么方法可以得到相同的结果结果就像 Pentaho 中的 pgAdmin,我不想使用 0 Screenshot from PEntaho Report Designer
进行归档
您可以在 SQL 查询中将您的值转换为字符串:
您可以简单地将您的值转换为 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
如果您想对结果值有更多的控制,您可以使用 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 (pgAdmin) 中执行此查询 select justify_interval('2000000 second');
时,它工作得很好,我得到了这个结果:23 天 03:33:20,但是当我将它用于 Pentaho Report designer 或 Pentaho CDE,我得到了这个结果:00 years 00 months 23 days .....,我的问题是:有什么方法可以得到相同的结果结果就像 Pentaho 中的 pgAdmin,我不想使用 0 Screenshot from PEntaho Report Designer
您可以在 SQL 查询中将您的值转换为字符串:
您可以简单地将您的值转换为 SQL:
中的 text 或 varcharselect 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