PostgreSQL 时间/日期函数和操作符

一、日期/时间操作符

下表演示了基本算术操作符的行为(+,*, 等):

 

 二、日期/时间函数

 

 

 

 

 

 

 二、区别

select now();
select CURRENT_DATE;
select CURRENT_TIME;
select CURRENT_TIMESTAMP;
select CURRENT_TIME(precision);
select CURRENT_TIMESTAMP(precision);
select LOCALTIME;
select LOCALTIMESTAMP;
select LOCALTIME(precision);
select LOCALTIMESTAMP(precision);

CURRENT_TIMECURRENT_TIMESTAMP传递带有时区的值;LOCALTIMELOCALTIMESTAMP传递的值不带时区。CURRENT_TIMECURRENT_TIMESTAMPLOCALTIME和 LOCALTIMESTAMP可以有选择地接受一个精度参数

select transaction_timestamp();
select statement_timestamp();
select clock_timestamp();
select timeofday();
transaction_timestamp()等价于CURRENT_TIMESTAMP,但是其命名清楚地反映了它的返回值。statement_timestamp()返回当前语句的开始时刻(更准确的说是收到 客户端最后一条命令的时间)。

clock_timestamp()返回真正的当前时间,timeofday()是一个有历史原因的PostgreSQL函数。和clock_timestamp()相似,timeofday()也返回真实的当前时间,但是它的结果是一个格式化的text串,而不是timestamp with time zone值。

now()是PostgreSQL的一个传统,等效于transaction_timestamp()

posted @ 2022-04-20 10:51  数据库集中营  阅读(500)  评论(0编辑  收藏  举报