当前位置:网站首页>Common PostgreSQL data operation notes: time
Common PostgreSQL data operation notes: time
2022-06-29 22:03:00 【Own platform nine and three quarters】
1. current time
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);
-- Example
SELECT CURRENT_TIME;
result :14:39:53.662522-05
SELECT CURRENT_DATE;
result :2001-12-23
SELECT CURRENT_TIMESTAMP;
result :2001-12-23 14:39:53.662522-05
SELECT CURRENT_TIMESTAMP(2);
result :2001-12-23 14:39:53.66-05
SELECT LOCALTIMESTAMP;
result :2001-12-23 14:39:53.662522
1.1. Time function
| function | Return type | describe | Example | result |
|---|---|---|---|---|
| age(timestamp, timestamp) | interval | Subtract the parameter , Generate a usage year 、 month ( Not just days ) Of “ Symbolization ” Result | age(timestamp ‘2001-04-10’, timestamp ‘1957-06-13’) | 43 year 9 month 27 Japan |
| age(timestamp) | interval | from current_date( In the middle of the night ) subtract | age(timestamp ‘1957-06-13’) | 43 years 8 mons 3 days |
| clock_timestamp() | timestamp with time zone | Current date and time ( Changes during statement execution ); See the first 9.9.4 section | ||
| current_date | date | The current date ; See the first 9.9.4 section | ||
| current_time | time with time zone | current time ( Time of day ); See the first 9.9.4 section | ||
| current_timestamp | timestamp with time zone | Current date and time ( When the current transaction starts ); See the first 9.9.4 section | ||
| date_part(text, timestamp) | double precision | Get subdomain ( Equivalent to extract); See the first 9.9.1 section | date_part(‘hour’, timestamp ‘2001-02-16 20:38:40’) | 20 |
| date_part(text, interval) | double precision | Get subdomain ( Equivalent to extract); See the first 9.9.1 section | date_part(‘month’, interval ‘2 years 3 months’) | 3 |
| date_trunc(text, timestamp) | timestamp | Truncate to specified precision ; See also section 9.9.2 section | date_trunc(‘hour’, timestamp ‘2001-02-16 20:38:40’) | 2001-02-16 20:00:00 |
| date_trunc(text, interval) | interval | Truncate to specified precision ; See also section 9.9.2 section | date_trunc(‘hour’, interval ‘2 days 3 hours 40 minutes’) | 2 days 03:00:00 |
| extract(field from timestamp) double precision | Get subdomain ; See the first 9.9.1 section | extract(hour from timestamp ‘2001-02-16 20:38:40’) | 20 | |
| extract(field from interval) | double precision | Get subdomain ; See the first 9.9.1 section | extract(month from interval ‘2 years 3 months’) | 3 |
| isfinite(date) | boolean | Test Limited Date ( No +/- Infinite ) | isfinite(date ‘2001-02-16’) | true |
| isfinite(timestamp) | boolean | Test finite timestamps ( No +/- Infinite ) | isfinite(timestamp ‘2001-02-16 21:28:30’) | true |
| isfinite(interval) | boolean | Test at finite intervals | isfinite(interval ‘4 hours’) | true |
| justify_days(interval) | interval | Adjust the interval like this 30 The day time period can be expressed as month | justify_days(interval ‘35 days’) | 1 mon 5 days |
| justify_hours(interval) | interval | Adjust the interval like this 24 An hour time period can be expressed as a day | justify_hours(interval ‘27 hours’) | 1 day 03:00:00 |
| justify_interval(interval) | interval | Use justify_days and justify_hours Adjust the interval , Use extra symbols to adjust | justify_interval(interval ‘1 mon -1 hour’) | 29 days 23:00:00 |
| localtime | time | current time ( Time of day ); See the first 9.9.4 section | ||
| localtimestamp | timestamp | Current date and time ( The start of the current transaction ); See the first 9.9.4 section | ||
| make_date(year int, month int, day int) | date | From the year 、 month 、 Date of creation of the day field | make_date(2013, 7, 15) | 2013-07-15 |
| make_interval(years int DEFAULT 0, months int DEFAULT 0, weeks int DEFAULT 0, days int DEFAULT 0, hours int DEFAULT 0, mins int DEFAULT 0, secs double precision DEFAULT 0.0) | interval | From the year 、 month 、 Zhou 、 Japan 、 when 、 branch 、 Second field creation | interval make_interval(days => 10) | 10 days |
| make_time(hour int, min int, sec double precision) | time | Since then 、 branch 、 Second field creation time | make_time(8, 15, 23.5) | 08:15:23.5 |
| make_timestamp(year int, month int, day int, hour int, min int, sec double precision) | timestamp | From the year 、 month 、 Japan 、 when 、 branch 、 Second field create timestamp | make_timestamp(2013, 7, 15, 8, 15, 23.5) | 2013-07-15 08:15:23.5 |
| make_timestamptz(year int, month int, day int, hour int, min int, sec double precision, [ timezone text ]) | timestamp with time zone | From the year 、 month 、 Japan 、 when 、 branch 、 The second field creates a timestamp with a time zone . If not specified timezone, Use the current time zone . | make_timestamptz(2013, 7, 15, 8, 15, 23.5) | 2013-07-15 08:15:23.5+01 |
| now() | timestamp with time zone | Current date and time ( The start of the current transaction ); See the first 9.9.4 section | ||
| statement_timestamp() | timestamp with time zone | Current date and time ( The start of the current transaction ); See the first 9.9.4 section | ||
| timeofday() | text | Current date and time ( image clock_timestamp, But as a text character string ); See the first 9.9.4 section | ||
| transaction_timestamp() | timestamp with time zone | Current date and time ( The start of the current transaction ); See the first 9.9.4 section | ||
| to_timestamp(double precision) | timestamp with time zone | hold Unix Time ( from 1970-01-01 00:00:00+00 The first second ) convert to timestamp | to_timestamp(1284352323) | 2010-09-13 04:32:03+00 |
边栏推荐
- Water polo chart - using dynamic ripples to show percentages
- 研发测试时间比,BUG数据分析
- 彩涂钢板密封板申请BS 476-3如何备样?
- Vipshop Keyword Search API interface (item_search- search vipshop commodity API interface by keyword), vipshop API interface
- Cloud native database query optimization - statistics and row count estimation
- 尚硅谷实时数据仓库项目(阿里云实时数仓)
- 细说GaussDB(DWS)复杂多样的资源负载管理手段
- Goahead webserver migration
- Huawei cloud AOM version 2.0 release
- Matlab output format control%d,%f,%c,%s usage
猜你喜欢

Simple analysis of wieshark packet capturing MySQL protocol

leetcode:370. Interval addition

华为云AOM 2.0版本发布

Divide the bonus pool of 10million + million yuan, and empower developers in the 2022 shengteng AI innovation competition

STM32 and gd32 notes

Knowledge distilling learning notes

What is a SYN Flood attack? How to protect?

ASP动态创建表格 Table

什么是 SYN 洪水攻击?如何防护?

STM32 minimum system construction (schematic diagram)
随机推荐
Star ring technology data security management platform defender heavy release
状态管理 利用Session限制页面访问 只有通过登录验证SessionLogin.aspx才能访问Session.aspx
Small library project summary
Goahead webserver migration
Data mining review
Shangsilicon Valley real-time data warehouse project (Alibaba cloud real-time data warehouse)
Numpy's research imitation 1
CLI tool foundation of ros2 robot f1tenth
Desai wisdom number - other charts (basic sunrise chart): high frequency words in graduation speech
R language plot visualization: plot visualization box graph and several box plots of multiple classification variables
Which brokerage commission is the lowest and safest
MySQL,MVCC详解,快照读在RC、RR下的区别
2022 openvino DevCon unveils secrets! Intel and many partners deepen the construction of developer ecology and release the innovation potential of AI industry
Don't worry about form deformation anymore
Information available from radar echo
BUAA OO unit 4 HW16 unit 4 Summary and course review
Taro applet enables wxml code compression
亚马逊商品详情API接口-(item_get-获得AMAZON商品详情接口),亚马逊详情API接口
Shell implementation of Memcache cache cache hit rate monitoring script
Flame retardant test of aluminum sheet as/nzs 1530.1 non combustible materials