PostgreSQL MySQL 兼容性之 - 时间类型

简介:
+关注继续查看

DATE

MySQL

  DATE
  A date. The supported range is '1000-01-01' to '9999-12-31'.
  '0000-00-00' is a permitted special value (zero-date), unless the NO_ZERO_DATE SQL_MODE is used.
  Also, individual components of a date can be set to 0 (for example: '2015-00-12'), unless the NO_ZERO_IN_DATE SQL_MODE is used.

PostgreSQL

  DATE
  但是PG不支持'0000-00-00', 通过改源码 ValidateDate, 自动将'0000-00-00'转存为'0001-01-01 BC'

TIME

MySQL

  TIME [(<microsecond precision>)]
  A time. The range is '-838:59:59.999999' to '838:59:59.999999'. Microsecond precision can be from 0-6; if not specified 0 is used. 

PostgreSQL

  TIME [(<microsecond precision>)]

DATETIME

MySQL

  DATETIME [(microsecond precision)]
  A date and time combination. The supported range is '1000-01-01 00:00:00.000000' to '9999-12-31 23:59:59.999999'. 
  MariaDB displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format, but allows assignment of values to DATETIME columns using either strings or numbers.
  '0000-00-00' is a permitted special value (zero-date), unless the NO_ZERO_DATE SQL_MODE is used. 
  Also, individual components of a date can be set to 0 (for example: '2015-00-12'), unless the NO_ZERO_IN_DATE SQL_MODE is used. 
  In many cases, the result of en expression involving a zero-date, or a date with zero-parts, is NULL. 
  If the ALLOW_INVALID_DATES SQL_MODE is enabled, if the day part is in the range between 1 and 31, the date does not produce any error, even for months that have less than 31 days.

PostgreSQL
timestamp [(microsecond precision)]
timestamptz [(microsecond precision)]

  char([M])

TIMESTAMP

MySQL

  TIMESTAMP [(<microsecond precision)]
  A timestamp in the format YYYY-MM-DD HH:MM:DD.
  The timestamp field is generally used to define at which moment in time a row was added or updated and by default will automatically be assigned the current datetime when a record is inserted or updated.

PostgreSQL

  timestamp [(microsecond precision)]
  timestamptz [(microsecond precision)]

YEAR

MySQL

  YEAR[(4)]
  A year in two-digit or four-digit format. The default is four-digit format. Note that the two-digit format has been deprecated since 5.5.27.
  In four-digit format, the allowable values are 1901 to 2155, and 0000.

PostgreSQL

  postgres=# create domain year as int2 constraint ck check (value between 1901 and 2155);
  CREATE DOMAIN
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
3天前
|
关系型数据库 MySQL 分布式数据库
直播预告 | MySQL & PostgreSQL 终极大比拼!
MySQL、PostgreSQL,乃至各种各样的数据库,孰强孰弱,难以辨别。究其原因,只因”不识庐山真面目,只缘身在此山中“。只需跳出”数据库“三字,一切自然看的分明。9月22日,解读如何换个维度,发现真相。
|
3天前
|
存储 关系型数据库 MySQL
PostgreSQL与MySQL优劣势比较浅谈
PostgreSQL与MySQL优劣势比较浅谈
9 0
|
5天前
|
SQL 关系型数据库 MySQL
功能强大的PostgreSQL没有MySQL流行的10个原因
本篇文章总结了为什么功能强大的PostgreSQL没有像MySQL一样流行的10个原因。玖章算术CEO叶正盛从产品功能、技术架构、生态、品牌商业等多个方面进行了分析,并指出了MySQL在流行度上的优势。文章还讨论了数据库在不同领域的竞争力和展望,并提到了PostgreSQL在中国信创产业发展中可能迎来新的机会。总体而言,这篇文章提供了关于MySQL和PostgreSQL的综合比较和评估。
23 0
功能强大的PostgreSQL没有MySQL流行的10个原因
|
6天前
|
Cloud Native OLAP 关系型数据库
云原生数据仓库AnalyticDB MySQL版/PostgreSQL版(二)
云原生数据仓库AnalyticDB MySQL版/PostgreSQL版(二)
34 0
|
7天前
|
存储 关系型数据库 分布式数据库
云原生关系型数据库Polar DB MySQL版(二)
云原生关系型数据库Polar DB MySQL版(二)
31 0
|
8天前
|
关系型数据库 MySQL 分布式数据库
PolarDB MySQL全球数据库(GDN)异地多活
PolarDB MySQL支持跨地域部署全球数据库,打通全国/全球企业用户的数据,数据保持同步且网络延迟不大于2秒。
394 1
|
8天前
|
关系型数据库 MySQL 分布式数据库
PolarDB MySQL HTAP:实时数据分析加速
本场景带您体验PolarDB MySQL的HTAP特性之列存索引(IMCI)。
79 0
|
8天前
|
SQL 关系型数据库 MySQL
|
8天前
|
关系型数据库 分布式数据库 数据库
PolarDB MySQL通过DMS恢复误操作数据
本场景介绍日常访问PolarDB MySQL数据库时,由于操作导致数据不符合预期,需要将数据快速恢复到正常状态。误操作受影响的数据量在10万以内时,可使用DMS数据追踪的方式恢复数据。
15 0
|
9天前
|
SQL 关系型数据库 分布式数据库
PolarDB for MySQL 多主集群体验
本实验带您体验PolarDB for MySQL多主集群跨机行级并发读写能力和跨机写性能的横向扩展。
19 0
相关产品
云数据库 Redis 版
云数据库 MongoDB 版
云数据库 RDS
推荐文章
更多