文档 / 函数百科 / 时间/日期函数和操作符
FUNCTION时间/日期函数和操作符
statement_timestamp
当前日期和时间(当前语句的开始);参见 Section 9.9.5
Current date and time (start of current statement); see Section 9.9.5
时间/日期函数和操作符 引入 9.0(基线) 现存至 20 devel 2 条签名 0 次签名变更
- 分组
- 时间/日期函数和操作符
- 签名数
- 2 条
- 引入版本
- 9.0(基线)
- 状态
- 现存
- 签名变更
- 未变过
- 本版来源
- 本站译文
版本轨迹
相对 PostgreSQL 17 无变化。
签名
PostgreSQL 18 里 statement_timestamp 的 2 条签名,按上游手册顺序排列。参数名用斜体,类型用弱化色, 之后是返回类型。说明取自本站手册译文:标「沿用」的借用了另一版的译文,标「EN」的本站暂无译文、按英文原文显示。
-
statement_timestamp( ) →timestamp with time zone当前日期和时间(当前语句的开始);参见 Section 9.9.5statement_timestamp()2019-12-23 14:39:53.662522-05
-
statement_timestamp()transaction_timestamp()等价于CURRENT_TIMESTAMP,但是其命名清楚地反映了它的返回值。statement_timestamp()返回当前语句的开始时刻(更准确的说是收到 客户端最后一条命令的时间)。statement_timestamp()和transaction_timestamp()在一个事务的第一条命令期间返回值相同,但是在随后的命令中却不一定相同。clock_timestamp()返回真正的当前时间,因此它的值甚至在同一条 SQL 命令中都会变化。timeofday()是一个有历史原因的PostgreSQL函数。和clock_timestamp()相似,timeofday()也返回真实的当前时间,但是它的结果是一个格式化的text串,而不是timestamp with time zone值。now()是PostgreSQL的一个传统,等效于transaction_timestamp()。
演化历史
相邻两个大版本之间的差异,新的在前。版本号链到该版的签名。
-
PostgreSQL 14 ← 13 说明更新
说明更新
-
PostgreSQL 13 ← 12 手册重排
这一跳手册重排了函数表的写法,签名文本整体改写,只记函数的增删,不逐条比较签名。
签名矩阵
每条签名在给出了签名的 18 个版本里的存在情况;方格指向该版的签名。只在正文里提到此函数、没有给出签名的版本不列进来,上面的版本轨迹里仍然有它们。签名文本在 PostgreSQL 13 前后写法不同,跨越那一跳的同一条签名会显示成两行。
存在 不存在
同组函数
| 函数 | 签名 | 主签名 | 版本变动 | 最近变更 |
|---|---|---|---|---|
age基线 |
3 | age ( timestamp, timestamp ) → interval |
— | |
| 减去参数,生成一个使用年和月,而不是只用日的“符号化”的结果 | 现存 | |||
clock_timestamp基线 |
2 | clock_timestamp ( ) → timestamp with time zone |
— | |
| 当前日期和时间(在语句执行期间变化);参见Section 9.9.5 | 现存 | |||
current_date基线 |
1 | current_date → date |
— | |
| 当前日期;参见 Section 9.9.5 | 现存 | |||
current_time基线 |
3 | current_time → time with time zone |
— | |
| 一天中的当前时间;参见 Section 9.9.5 | 现存 | |||
current_timestamp基线 |
3 | current_timestamp → timestamp with time zone |
— | |
| 当前日期和时间 (当前事务的开始);参见 Section 9.9.5 | 现存 | |||
date_add |
1 | date_add ( timestamp with time zone, interval [, text ] ) → timestamp with time zone |
— | |
| 将一个 interval 加到 timestamp with time zone 上,并根据第三个参数命名的时区,或在省略该参数时根据当前TimeZone设置,计算时刻和夏令时调整。 | 现存 | |||
date_bin |
2 | date_bin ( interval, timestamp, timestamp ) → timestamp |
— | |
| 将输入按指定的间隔进行分箱(bin),对齐到指定的原点;参见Section 9.9.3 | 现存 | |||
date_part基线 |
3 | date_part ( text, timestamp ) → double precision |
— | |
| 获取时间戳字段 (等同于 extract);参见 Section 9.9.1 | 现存 | |||
date_subtract |
1 | date_subtract ( timestamp with time zone, interval [, text ] ) → timestamp with time zone |
— | |
| 从一个 timestamp with time zone 中减去 interval,并根据第三个参数命名的时区,或在省略该参数时根据当前TimeZone设置,计算时刻和夏令时调整。 | 现存 | |||
date_trunc基线 |
4 | date_trunc ( text, timestamp ) → timestamp |
183 次 | |
| 截断到指定的精度;参见 Section 9.9.2 | 现存 | |||
extract基线 |
3 | extract ( field FROM timestamp ) → numeric |
192 次 | |
| 获取时间戳子字段;参见 Section 9.9.1 | 现存 | |||
isfinite基线 |
3 | isfinite ( date ) → boolean |
— | |
| 测试有限日期(不是+/-无限) | 现存 | |||
justify_days基线 |
1 | justify_days ( interval ) → interval |
— | |
| 调整间隔,将30天的时间段转换为月份 | 现存 | |||
justify_hours基线 |
1 | justify_hours ( interval ) → interval |
— | |
| 调整间隔,将24小时时间段转换为天数 | 现存 | |||
justify_interval基线 |
1 | justify_interval ( interval ) → interval |
— | |
| 使用 justify_days 和 justify_hours调整时间间隔; 通过额外的符号调整 | 现存 | |||
localtime基线 |
3 | localtime → time |
— | |
| 一天中当前时间;参见 Section 9.9.5 | 现存 | |||
localtimestamp基线 |
3 | localtimestamp → timestamp |
— | |
| 当前日期和时间(当前事务的开始);参见 Section 9.9.5 | 现存 | |||
make_date |
1 | make_date ( year int, month int, day int ) → date |
— | |
| 从年、月和日字段创建日期(负数年份表示BC) | 现存 | |||
make_interval |
1 | make_interval ( [ years int [, months int [, weeks int [, days int [, hours int [, mins int [, secs double precision ]]]]]]] ) → interval |
— | |
| 从年、月、周、日、小时、分钟和秒字段创建时间间隔,每个字段默认为0 | 现存 | |||
make_time |
1 | make_time ( hour int, min int, sec double precision ) → time |
— | |
| 从小时、分钟和秒字段创建时间 | 现存 | |||
make_timestamp |
1 | make_timestamp ( year int, month int, day int, hour int, min int, sec double precision ) → timestamp |
— | |
| 从年、月、日、小时、分钟和秒字段创建时间戳(负数年份表示BC) | 现存 | |||
make_timestamptz |
1 | make_timestamptz ( year int, month int, day int, hour int, min int, sec double precision [, timezone text ] ) → timestamp with time zone |
— | |
| 从年,月,日,小时,分钟和秒字段结合时区创建时间戳(负数年份表示BC)。 | 现存 | |||
now基线 |
2 | now ( ) → timestamp with time zone |
— | |
| 当前日期和时间(当前事务的开始);参见 Section 9.9.5 | 现存 | |||
pg_sleep基线 |
1 | pg_sleep ( double precision ) |
— | |
| pg_sleep使当前会话的进程休眠,直到过去给定的秒数。 | 现存 | |||
pg_sleep_for |
1 | pg_sleep_for ( interval ) |
— | |
| pg_sleep使当前会话的进程休眠,直到过去给定的秒数。 | 现存 | |||
pg_sleep_until |
1 | pg_sleep_until ( timestamp with time zone ) |
— | |
| pg_sleep使当前会话的进程休眠,直到过去给定的秒数。 | 现存 | |||
statement_timestamp基线 |
2 | statement_timestamp ( ) → timestamp with time zone |
— | |
| 当前日期和时间(当前语句的开始);参见 Section 9.9.5 | 现存 | |||
timeofday基线 |
2 | timeofday ( ) → text |
— | |
| 当前的日期和时间 (类似 clock_timestamp, 但是采用 text 字符串);参见 Section 9.9.5 | 现存 | |||
transaction_timestamp基线 |
2 | transaction_timestamp ( ) → timestamp with time zone |
— | |
| 当前日期和时间(当前事务的开始);参见 Section 9.9.5 | 现存 | |||