关于date 数据类型,Oracle 与 PostgreSQL 格式是不同的,Oracle 是 日期 + 时间的类型,而PG 则只有日期。
KingbaseES Oracle 模式则同时实现了二者类型,用户在使用时,需要注意所使用的类型。
查 sys_type 可以看到有两个 date 类型,这两个类型在不同的模式下:
test=# select typname,typnamespace::regnamespace from sys_type where typname='date';
typname | typnamespace
---------+--------------
date | pg_catalog
date | sys
sys.date是兼容Oracle date 类型。 通过 current_schemas 可以确认用户最优先的schema 是sys ,也就是默认使用的是 sys.date 类型:
test=# select current_schemas(true);
current_schemas
-------------------------------------
{sys,pg_catalog,sys_catalog,public}
创建同时包含两种date 类型的表:
test=# set nls_date_format='yyyy-mm-dd hh24:mi:ss';
SET
test=# create table t_date(id1 pg_catalog.date,id2 date);
CREATE TABLE
test=# insert into t_date values('2021-01-01','2021-01-01');
INSERT 0 1
test=# select * from t_date;
id1 | id2
------------+---------------------
2021-01-01 | 2021-01-01 00:00:00
(1 row)
注意:这里设置了 nls_date_format ,否则与 Oracle 类似,默认只显示 日期。
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




