2016-08-09 6 views
1

からレポートデザイナーjustify_intervalクエリ私はPostgreSQLでこのクエリselect justify_interval('2000000 second');を実行しよう(pgAdminで)それが仕事完璧私はこの結果を持っていた:23日午前3時33分20秒を、私はPentahoのにそれを使用するときレポートデザイナーまたはPentaho CDEの場合、私はこの結果を持っていました:00年00ヶ月23日.....、私の質問は:ペンタホ州のpgAdminと同じ結果を得る方法はありますか? Screenshot from PEntaho Report DesignerPentahoのCDE、PostgreSQLの

答えて

1

とfiledsあなたは、SQLクエリで文字列にあなたの値を変換することができます

    あなたは、単にSQLにあなたのテキストに値またはvarcharをキャストすることができます
  1. 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

+0

はこの参考になっ答えてくれてありがとう、それは完璧に動作します – YassIne

関連する問題