EDB日期类型的一个问题

本人花费半年的时间总结的《Java面试指南》已拿腾讯等大厂offer,已开源在github ,欢迎star!

本文GitHub https://github.com/OUYANGSIHAI/JavaInterview 已收录,这是我花了6个月总结的一线大厂Java面试总结,本人已拿大厂offer,欢迎star

原文链接:blog.ouyangsihai.cn >> EDB日期类型的一个问题

EDB日期类型的一个问题

最近有位同事问了一个,和EDB日期类型相关的问题,看起来很有意思,但实际和EDB原理有一些关系,使用客户端工具,创建新表,字段名称a,类型选择的是date,

EDB日期类型的一个问题

保存完成,此时类型显示的则是timestamp,长度6,并不是之前的date,

EDB日期类型的一个问题

开始以为是客户端的问题,使用SQL语句,

create table a(
a date;
);

执行完成,发现类型就是timestamp,不是语句定义的date,难道有类型限制?

经过雪哥指点,从官方手册和官网上,找到了些许答案,

https://www.enterprisedb.com/docs/en/9.3/oracompat/Database_Compatibility_for_Oracle_Developers_Guide.1.032.html#pID0E0BZT0HA

When DATE appears as the data type of a column in the commands, it is translated to TIMESTAMP(0) at the time the table definition is stored in the database if the configuration parameter edb_redwood_date is set to TRUE. Thus, a time component will also be stored in the column along with the date. This is consistent with Oracle’s DATE data type.

When DATE appears as the data type of a column in the data definition language (DDL) commands, CREATE TABLE or ALTER TABLE, it is translated to TIMESTAMP(0) at the time the table definition is stored in the database. Thus, a time component will also be stored in the column along with the date.

If edb_redwood_date is set to FALSE the column’s data type in a CREATE TABLE or ALTER TABLE command remains as a native PostgreSQL DATE data type and is stored as such in the database. The PostgreSQL DATE data type stores only the date without a time component in the column.

Regardless of the setting of edb_redwood_date, when DATE appears as a data type in any other context such as the data type of a variable in an SPL declaration section, or the data type of a formal parameter in an SPL procedure or SPL function, or the return type of an SPL function, it is always internally translated to a TIMESTAMP(0) and thus, can handle a time component if present.

TIMESTAMP accepts an optional precision value p which specifies the number of fractional digits retained in the seconds field. The allowed range of p is from 0 to 6 with the default being 6.

When TIMESTAMP values are stored as double precision floating-point numbers (currently the default), the effective limit of precision may be less than 6. TIMESTAMP values are stored as seconds before or after midnight 2000-01-01. Microsecond precision is achieved for dates within a few years of 2000-01-01, but the precision degrades for dates further away.

When TIMESTAMP values are stored as eight-byte integers (a compile-time option), microsecond precision is available over the full range of values. However eight-byte integer timestamps have a more limited range of dates than shown above: from 4713 BC up to 294276 AD.  TIMESTAMP (p) WITH TIME ZONE is similar to TIMESTAMP (p), but includes the time zone as well.

EDB中的日期类型,

EDB日期类型的一个问题

介绍的比较清楚,简单来讲,就是有一个参数,edb_redwood_date控制DATE类型是否含有时间,如果需要和Oracle兼容,则设置为TRUE,

https://www.enterprisedb.com/docs/en/9.3/oracompat/Database_Compatibility_for_Oracle_Developers_Guide.1.005.html#pID0E0PHV0HA

edb_redwood_date – Controls whether or not a time component is stored in DATE columns. For Oracle compatible behavior, set edb_redwood_date to TRUE.

参数默认值为false,可以session级别修改,

EDB日期类型的一个问题

看下当前库中,该参数值设置为on,

EDB日期类型的一个问题

设置参数值为off,

EDB日期类型的一个问题

执行建表语句,

create table a(
a date;
);

此时类型就是date,不是timestamp,

EDB日期类型的一个问题

之前我们说过,《》,EDB是语法上最兼容Oracle的数据库,但其核心还是PG,因此为了兼容,就可能要支持两种用法,相应地就要有参数可以控制,相当于开关操作。PG中的DATE类型仅含有日期,不含有时间,这和Oracle中的DATE,有些不同,于是出现了edb_redwood_date参数,可以控制和Oracle的兼容性,之所以此处值为true不是false,推测有可能因为安装的时候,选择兼容Oracle,因此参数会以兼容Oracle为准。

如果您觉得本文有帮助,欢迎关注转发:bisal的个人杂货铺,

EDB日期类型的一个问题 EDB日期类型的一个问题
本人花费半年的时间总结的《Java面试指南》已拿腾讯等大厂offer,已开源在github ,欢迎star!

本文GitHub https://github.com/OUYANGSIHAI/JavaInterview 已收录,这是我花了6个月总结的一线大厂Java面试总结,本人已拿大厂offer,欢迎star

原文链接:blog.ouyangsihai.cn >> EDB日期类型的一个问题


 上一篇
EDB是什么数据库? EDB是什么数据库?
最近某一个尘封多年的产品,需要重新启动,原来用的数据库就是EDB,可能有些朋友听起来,觉得有些新鲜,EDB数据库?可能国内听说的比较少,但说到PG即PostgreSQL,可能朋友们就比较熟悉了,作为一款开源数据库,PG的流行程度
下一篇 
如何统计表的活跃度? 如何统计表的活跃度?
最近有朋友问了一个问题, 如何统计出表的活跃度?即统计出经常被访问使用的表。 我觉得有几种思路, 应用记录日志,可以根据需要,更精确地统计,满足各种定制化需求。 可以使用数据库审计功能,支持各种粒度的审计,但是会有些消耗,