pg 中日期型的計算問題

babyyellow發表於2012-04-20
oracle 中關於時間型別的計算是相當的簡單的,
oracle 對時間型別的計算 對運算子進行的過載。

pg 裡的時間的計算比oracle 要弱不少,目前只實現了 date 型別的 “+” 操作

例如:
1cyp_nw_app=> select current_date +7 ,current_date ;
2  ?column?  |    date   
3------------+------------
4 2012-04-27 | 2012-04-20


對於time ,timestamp 型別的加減操作,操作的因子是要 interval 型別的資料的
例如:
01cyp_nw_app=>   select interval '7days' ;
02 interval
03----------
04 7 days
05 
06 
07cyp_nw_app=> select current_timestamp , current_timestamp + interval '7d';
08              now              |           ?column?           
09-------------------------------+-------------------------------
10 2012-04-20 15:07:31.425797+08 | 2012-04-27 15:07:31.425797+08
11(1 DD????)
12 
13cyp_nw_app=> select current_timestamp , current_timestamp + interval '7Y';
14              now              |           ?column?           
15-------------------------------+-------------------------------
16 2012-04-20 15:07:37.165961+08 | 2019-04-20 15:07:37.165961+08
17(1 DD????)
18 
19cyp_nw_app=> select current_timestamp , current_timestamp + interval '7m';
20              now              |           ?column?           
21-------------------------------+-------------------------------
22 2012-04-20 15:07:46.186136+08 | 2012-04-20 15:14:46.186136+08
23(1 DD????)
24 
25cyp_nw_app=> select current_timestamp , current_timestamp + interval '7w';
26              now              |           ?column?           
27-------------------------------+-------------------------------
28 2012-04-20 15:07:52.080267+08 | 2012-06-08 15:07:52.080267+08
29(1 DD????)
30 
31cyp_nw_app=> select current_timestamp , current_timestamp + interval '7s';
32              now              |           ?column?           
33-------------------------------+-------------------------------
34 2012-04-20 15:07:56.222229+08 | 2012-04-20 15:08:03.222229+08
35(1 DD????)
36 
37cyp_nw_app=> select current_timestamp , current_timestamp + interval '7h';
38              now              |           ?column?           
39-------------------------------+-------------------------------
40 2012-04-20 15:08:04.816308+08 | 2012-04-20 22:08:04.816308+08
41(1 DD????)

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/133735/viewspace-721807/,如需轉載,請註明出處,否則將追究法律責任。

相關文章