PostgreSQL中with和without time zone两者有什么区别
with和without time zone两者有什么区别
1.区别
1)名字上看一个是带时区的,另一个是不带时区的,查出来的时间是一样的,只是一个带时区标志,一个不带而已,时区的基准是格林威治时间UTC。
2)这对于数据的显示上来说,区别就是时间数据的末尾带不带时区标志,即+/-时区,比如中国(prc),时区是东八区,带时区标志的话就是+08。
数据库内部还是都存储的是UTC格式时间,根据当前的时区进行转换显示。
2.查看配置文件中时区的配置:
[postgres@localhost ~]$ more /database/pgdata/postgresql.conf |grep timezone
log_timezone = 'US/Pacific'
timezone = 'US/Pacific'
#timezone_abbreviations = 'Default' # Select the set of available time zone
# share/timezonesets/.
3.客户端时区的更改说明
在服务端有一些时区的配置信息,安装的时候就给装上了,客户端时区的更改并不能随意设置。
这些配置信息是放在$PGHOME/share/timezone里面。
4.实验:
美国西7区与中国东八区相差15个小时,格林威治时间UTC和东八区相差8个小时
test=# set timezone="US/Pacific";
SET
test=# show timezone;
TimeZone
------------
US/Pacific
( row) test=# select now()::timestamp with time zone, now()::timestamp without time zone;
now | now
-------------------------------+----------------------------
-- ::47.578319- | -- ::47.578319
( row) test=# set timezone=prc;
SET
test=# show timezone;
TimeZone
----------
PRC
( row) test=# select now()::timestamp with time zone, now()::timestamp without time zone;
now | now
-------------------------------+----------------------------
-- ::01.898303+ | -- ::01.898303
( row) test=# set timezone=UTC;
SET
test=# show timezone;
TimeZone
----------
UTC
( row) test=# select now()::timestamp with time zone, now()::timestamp without time zone;
now | now
-------------------------------+----------------------------
-- ::09.018571+ | -- ::09.018571
( row)
北京、上海都是PRC东八区,时间是一样的
test=# set timezone="Asia/Shanghai";
SET
test=# show timezone;
TimeZone
---------------
Asia/Shanghai
( row) test=# select now()::timestamp with time zone, now()::timestamp without time zone;
now | now
-------------------------------+----------------------------
-- ::26.704907+ | -- ::26.704907
( row) test=# set timezone="Asia/Beijing";
SET
test=# select now()::timestamp with time zone, now()::timestamp without time zone;
now | now
-------------------------------+----------------------------
-- ::41.534930+ | -- ::41.534930
( row) test=# set timezone=PRC;
SET
test=# select now()::timestamp with time zone, now()::timestamp without time zone;
now | now
-------------------------------+----------------------------
-- ::54.704583+ | -- ::54.704583
( row)
PostgreSQL中with和without time zone两者有什么区别的更多相关文章
- 通过arcgis在PostgreSQL中创建企业级地理数据库
部署环境: Win7 64位旗舰版 软件版本: PostgreSQL-9.1.3-2-windows-x64 Postgis-pg91x64-setup-2.0.6-1 Arcgis 10.1 SP1 ...
- PostgreSQL 中日期类型转换与变量使用及相关问题
PostgreSQL中日期类型与字符串类型的转换方法 示例如下: postgres=# select current_date; date ------------ 2015-08-31 (1 row ...
- PostgreSQL 中定义自己需要的数据类型
PostgreSQL解决某系数据库中的tinyint数据类型问题,创建自己需要的数据类型如下: CREATE DOMAIN tinyint AS smallint CONSTRAINT tinyint ...
- 在PostgreSQL中使用oracle_fdw访问Oracle
本文讲述如何在PostgreSQL中使用oracle_fdw访问Oracle上的数据. 1. 安装oracle_fdw 可以参照:oracle_fdw in github 编译安装oracle_fdw ...
- [原创]PostgreSQL中十进制、二进制、十六进制之间的相互转换
在PostgreSQL中,二进制.十进制.十六进制之间的转换是非常方便的,如下: 十进制转十六进制和二进制 mydb=# SELECT to_hex(10); to_hex -------- a (1 ...
- 用python随机生成数据,再插入到postgresql中
用python随机生成学生姓名,三科成绩和班级数据,再插入到postgresql中. 模块用psycopg2 random import random import psycopg2 fname=[' ...
- PostgreSQL 中如何实现group_concat
之前在MySQL中使用group_concat,觉得超级好用. 今天在PostgreSQL需要用到这样的场景,就去学习了一下. 在PostgreSQL中提供了arr_agg的函数来实现聚合,不过返回的 ...
- Postgresql中临时表(temporary table)的特性和用法
熟悉Oracle的人,相比对临时表(temporary table)并不陌生,很多场景对解决问题起到不错的作用,开源库Postgresql中,也有临时表的概念,虽然和Oracle中临时表名字相同,使用 ...
- PostgreSQL中JSON、JSONB基本操作符
PostgreSQL 9.5以上的版本中有了很多方便的操作符,使得操作 JSON 变得非常方便了. 一. -> 和 ->> : -> 表示获取一个JSON数组元素,支持下标值( ...
随机推荐
- URAL 2092 Bolero 贪心
C - Bolero Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit S ...
- 解决xshell无法连接virtualbox中的虚拟机(Ubuntu18.04)的问题
遇到这个问题第一反应是是否安装相应的组件: sudo apt-get install openssh-server 开启防火墙端口 firewall-cmd --zone=/tcp --permane ...
- delphi通过url下载文件
procedure TfrmEngineerImport.btnDownloadClick(Sender: TObject);var vsql, SourceFile, DestFile, filen ...
- 使用fiddler实现手机抓包
手机上无法直接查看网络请求数据,需要使用抓包工具.Fiddler是一个免费的web调试代理,可以用它实现记录.查看和调试手机终端和远程服务器之间的http/https通信. fiddler没有手机客户 ...
- ZooKeeper分布式锁的实现原理
七张图彻底讲清楚ZooKeeper分布式锁的实现原理[石杉的架构笔记] 文章转载自:https://juejin.im/post/5c01532ef265da61362232ed#comment(写的 ...
- Java 注解方式校验请求参数
1. 参数校验常用注解 注解 验证的数据类型 备注 Null 任意类型 参数值必须是 Null NotNull ...
- Linux上Python的安装升级
1.下载 cd /usr/local/src/ wget https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tgz 2.安装,在/usr/loc ...
- 转发:Java对象及其引用
原文: http://zwmf.iteye.com/blog/1738574 Java对象及其引用 关于对象与引用之间的一些基本概念. 初学Java时,在很长一段时间里,总觉得基本概念很模糊.后来才知 ...
- Failed to start LSB: start and stop MariaDB
Failed to start LSB: start and stop MariaDB */--> Failed to start LSB: start and stop MariaDB Tab ...
- (转)js控制窗口失去焦点(包括屏蔽Alt+Tab键切换页面)
本章内容转自:http://www.cnblogs.com/BoKeYuanVinson/articles/3360954.html 转载自网络贴吧: 页面脚本是无法截获alt键的,不过可以变通一下, ...