postgresql timestamp timestamptz 使用注意事项
来源:互联网 发布:莆田精仿鞋淘宝网店 编辑:程序博客网 时间:2024/06/08 02:11
原创,转载请注明出处!
postgresql日期时间类型分为timestamp [ (p) ] [ without time zone ]和timestamp [ (p) ] with time zone,它们的区别在于一个无时区,另一有时区,存储大小均为8字节.
同时也要注意time [ (p) ] [ without time zone ]和time [ (p) ] with time zone类型,无时区存储大小为8字节,有时区存储大小为12字节.
postgresql中日期时间类型缩写:
timestamp
timestamptz
date (仅年月日部份,存储大小为4字节)
time
timetz
interval(表示间隔,存储大小为16字节)
interval可以通过函数make_interval来创建,支持年\月\星期\天\小时\分钟\秒的间隔.如now() + make_interval(days => 10)表示10天后,now() - make_interval(secs => 30)表示30秒之前
为保证数据的准确性在保存\使用\计算过程中应尽量使用timestamptz和timetz,尽量避免使用timestamp和time
UTC+8(EAT - 东亚标准时间/中国标准时间(BJT))
注意整个中国使用相同的时区,这就使得这个时区特别的大。在中国最西部的地区,太阳最高的时候是下午3点,在最东部是上午11点。单纯从地理规划来看,整个中国横跨了从东五区(UTC+5)到东九区(UTC+9)共计五个时区。
在postgresql中查询时区的定义
select * from pg_timezone_names
或查询东亚/中国时区定义
select * from pg_timezone_names where utc_offset = '+08:00:00';
查询结果中的"PRC","Asia/Shanghai","Asia/Chongqing"均表示中国
生成一个日期时间示例
select make_timestamptz(1970,1,1,0,0,0.0,'Asia/Shanghai')
注意避免使用timestamp类型相关函数,如:make_timestamp
[日期/时间类型]https://www.postgresql.org/docs/current/static/datatype-datetime.html
[日期/时间函数和操作符]https://www.postgresql.org/docs/current/static/functions-datetime.html
- postgresql timestamp timestamptz 使用注意事项
- PostgreSQL使用注意事项
- timestamp[] postgresql
- SQL Server中,timestamp类型使用注意事项
- PostgreSql中的timestamp用法
- PostgreSQL: 浅谈 PostgreSQL 的 timestamp 类型
- postgresql timestamp的精度问题
- 浅谈 PostgreSQL 的 timestamp 类型
- 浅谈 PostgreSQL 的 timestamp 类型
- PostgreSQL学习第八篇--psql的使用技巧和注意事项
- mysql timestamp/current_timestamp设置注意事项
- mysql timestamp/current_timestamp设置注意事项
- postgresql安装注意事项
- hibernate4 操作postgresql 注意事项
- 关于postgresql的注意事项
- PostgreSQL 数据类型手册【serial, timestamp,text....】
- PostgreSQL中timestamp相关的SQL语句
- Postgresql修改存储位置注意事项
- postgresql使用SSD页大小优化
- ES6---扩展运算符和rest‘...’(三点运算符),在数组、函数、set/map等中的应用
- PostgreSQL调整检查点的基础
- postgresql内存表
- postgresql取随机记录
- postgresql timestamp timestamptz 使用注意事项
- Eureka error "java.net.UnknownHostException: c1438e0d5866
- 清空postgresql shared_buffers
- postgresql10改进说明(翻译)
- PostgreSQL Windows简易安装
- PostgreSQL C风格的自定义函数FuncCallContext结构体描述及示例
- Spring核心类介绍
- PostgreSQL C风格函数TEXT优化
- 应用数据科学的现状:近期观察机器学习实际应用的趋势和对关键瓶颈的探讨