Ticket #19 (closed task 任务: fixed)

Opened 14 years ago

Last modified 14 years ago

pg 中关于日期类型的计算问题

Reported by: lisiliang Owned by: lslaing
Priority: major Milestone: PG 测试计划进程
Component: component1 Version:
Keywords: Cc:
Due Date: 20/04/2012

Description

oracle 中关于时间类型的计算是相当的简单的,
oracle 对时间类型的计算 对运算符进行的重载。

pg 里的时间的计算比oracle 要弱不少,目前只实现了 date 类型的 “+” 操作

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

对于time ,timestamp 类型的加减操作,操作的因子是要 interval 类型的数据的
例如:
01 cyp_nw_app=> select interval '7days' ;
02 interval
03 ----------
04 7 days
05
06
07 cyp_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
13 cyp_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
19 cyp_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
25 cyp_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
31 cyp_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
37 cyp_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????)

Change History

comment:1 Changed 14 years ago by lisiliang

  • Status changed from new to closed
  • Resolution set to fixed
Note: See TracTickets for help on using tickets.