博客
关于我
Postgresql 日期和时间类型
阅读量:376 次
发布时间:2019-03-05

本文共 1783 字,大约阅读时间需要 5 分钟。

 作者:瀚高PG实验室 (Highgo PG Lab)- 天蝎座

timestamp with[out] time zone    日期时间(时区)  time with[out] time zone   		 只用于一日内的时间(时区)    可以精确到毫秒。MySQL只能到秒。默认都不会显示时区,需要显示的指定with time zone。highgo=# select time '120900';   time   ---------- 12:09:00(1 row)highgo=# select time '120900 PST';   time   ---------- 12:09:00(1 row)highgo=# select time WITH time zone '120900 PST';   timetz    ------------- 12:09:00-08(1 row)在输入日期时,有很多种格式。有时候需要确定datestyle。highgo=# create table t(date date);CREATE TABLEhighgo=# insert into t values (date '12-18-2010');INSERT 0 1highgo=# select * from t;    date    ------------ 2010-12-18(1 row)highgo=# show datestyle; DateStyle ----------- ISO, MDY(1 row)highgo=# set datestyle = 'YMD';SEThighgo=# insert into t values (date '2010-12-19');INSERT 0 1highgo=# select * from t;    date    ------------ 2010-12-18 2010-12-19(2 rows)注: 建议使用 2017-12-18 这种方式输入日期。任何方式下都是2017年12月18日。PostgreSQL 提供可许多返回当前日期和时间的函数。部分函数按照当前事务的开始时刻返回结果:CURRENT_DATECURRENT_TIMECURRENT_TIMESTAMPCURRENT_TIME(precision)LOCALTIMELOCALTIMESTAMPnow()transaction_timestamp()  感觉这个描述更符合实际情况另外部分函数返回实时时间值,在事务中也会随时间变化。statement_timestamp()clock_timestamp()timeofday()              返回的是text字符串在同一个事务中,和now()同类型的函数不会变化,和statement_timestamp()同类型的函数则相反。highgo=# begin;BEGINhighgo=# select now();              now              ------------------------------- 2017-12-18 12:18:32.263891+08(1 row)highgo=# select now();              now              ------------------------------- 2017-12-18 12:18:32.263891+08(1 row)highgo=# select statement_timestamp();      statement_timestamp      ------------------------------- 2017-12-18 12:19:15.463267+08(1 row)highgo=# select statement_timestamp();      statement_timestamp      ------------------------------- 2017-12-18 12:19:18.975693+08(1 row)highgo=# commit;COMMIT

 

转载地址:http://qcowz.baihongyu.com/

你可能感兴趣的文章
IDEA出现问题:Received fatal alert: protocol_version 解决方案
查看>>
Airtest自动化测试 Docs airtest.core.android package
查看>>
SVN Unable to connect to a repository at URL 的解决方案
查看>>
Android基本知识
查看>>
命令模式【Command Pattern】
查看>>
OSI 7 层网络模型
查看>>
JDK 内置的多线程协作工具类的使用场景
查看>>
Java 中哪些对象可以获取类对象
查看>>
linux 的 cp 命令如何复制不提示覆盖
查看>>
linux 的 sleep 命令
查看>>
js 的 let var const 区别
查看>>
11.2.6 时间值的小数秒
查看>>
11.2.7 日期和时间类型之间的转换
查看>>
redis 内存溢出_从数据存储的角度告诉你Redis为什么这么快!
查看>>
实例分析Facebook激励视频广告接入
查看>>
实例:使用OKGO下载网络压缩包资源,然后解压缩放在本地使用
查看>>
解决mybatis嵌套查询使用PageHelper分页不准确
查看>>
Redis源码分析(七)--- zipmap压缩图
查看>>
大规模集群自动化部署工具--Chef的安装部署
查看>>
自定义Hive Sql Job分析工具
查看>>