
何となく雑多なメモです。使用した
(1)10 進数との乗除算ができる
select interval '1minute' * 100; +----------+ | ?column? | +----------+ | 01:40:00 | +----------+ -- 100 minutes -> 1 hour and 40 minutes select interval '1day' / 5; +----------+ | ?column? | +----------+ | 04:48:00 | +----------+ -- 1 / 5 day -> 4 hour and 48 minutes

日付・時刻型との加減算に比べて余り使わないけど。また乗算は、わざわざ使わなくても ↓ のように定義すれば済みますが、割り算は結構便利。
select interval '100minute'; +----------+ | ?column? | +----------+ | 01:40:00 | +----------+
(2)定義する書式が柔軟
select interval '100minute', -- 単位が単数形, 空白なし interval '100 minute', -- 〃 空白あり interval '100minutes', -- 単位が複数形, 空白なし interval '100 minutes'; -- 〃 空白あり +----------+ | ?column? | +----------+ | 01:40:00 | +----------+

基本的に「数値
(3)日付・時刻型との減算で、interval と明示しないとエラー
select now() + '1 month', -- 1ヶ月後 now() - interval '1 month'; -- 1ヶ月前 +-------------------------------+-------------------------------+ | ?column? | ?column? | +-------------------------------+-------------------------------+ | 2016-07-16 20:35:15.368672+09 | 2016-05-16 20:35:15.368672+09 | +-------------------------------+-------------------------------+ (1 row) select now() - '1 month'; -- 減算ではinterval省けないERROR: invalid input syntax for type timestamp with time zone: "1 month" at character 16 STATEMENT: select now() - '1 month'; ERROR: invalid input syntax for type timestamp with time zone: "1 month" LINE 1: select now() - '1 month'; ^

これは不便というか、最近ちょっと嵌った点。足し算は
select -'1 day' :: interval; +----------+ | ?column? | +----------+ | -1 days | +----------+ (1 row)
(4)10 進数の時間単位に変換するのは、自前で工夫
select date_trunc('hour', intv), extract(hour from intv), justify_hours(intv) from cast('0:59:59' as interval) as intv -- ほぼ1時間なので、10進数にして丸めたいが、適当な関数がない ; +------------+-----------+---------------+ | date_trunc | date_part | justify_hours | +------------+-----------+---------------+ | 00:00:00 | 0 | 00:59:59 | +------------+-----------+---------------+ (1 row) select extract(epoch from intv) / extract(epoch from interval '1hour') from cast('0:59:59' as interval) as intv -- いったん秒に変換して、当該単位の秒数で割れば10進数 ; +-------------------+ | ?column? | +-------------------+ | 0.999722222222222 | +-------------------+ (1 row)

もしかして何か関数があるかもしれないけど、今のところ不明。例えば
で、上のように