pg 中日期型的计算问题

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/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/133735/viewspace-721807/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值