博客
关于我
Postgresql 日期和时间类型
阅读量:387 次
发布时间: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/

你可能感兴趣的文章
MySQL-连接
查看>>
mysql-递归查询(二)
查看>>
MySQL5.1安装
查看>>
mysql5.5和5.6版本间的坑
查看>>
mysql5.5最简安装教程
查看>>
mysql5.6 TIME,DATETIME,TIMESTAMP
查看>>
mysql5.6.21重置数据库的root密码
查看>>
Mysql5.6主从复制-基于binlog
查看>>
MySQL5.6忘记root密码(win平台)
查看>>
MySQL5.6的Linux安装shell脚本之二进制安装(一)
查看>>
MySQL5.6的zip包安装教程
查看>>
mysql5.7 for windows_MySQL 5.7 for Windows 解压缩版配置安装
查看>>
Webpack 基本环境搭建
查看>>
mysql5.7 安装版 表不能输入汉字解决方案
查看>>
MySQL5.7.18主从复制搭建(一主一从)
查看>>
MySQL5.7.19-win64安装启动
查看>>
mysql5.7.19安装图解_mysql5.7.19 winx64解压缩版安装配置教程
查看>>
MySQL5.7.37windows解压版的安装使用
查看>>
mysql5.7免费下载地址
查看>>
mysql5.7命令总结
查看>>