diff --git "a/content/zh/post/gaoyunlong/PostgreSQL\344\270\216openGauss\344\271\213\345\205\263\351\224\256\345\255\227.md" "b/content/zh/post/gaoyunlong/PostgreSQL\344\270\216openGauss\344\271\213\345\205\263\351\224\256\345\255\227.md" new file mode 100644 index 0000000000000000000000000000000000000000..cb52a017939f8af6d88dcdecc5e4e82039dda305 --- /dev/null +++ "b/content/zh/post/gaoyunlong/PostgreSQL\344\270\216openGauss\344\271\213\345\205\263\351\224\256\345\255\227.md" @@ -0,0 +1,127 @@ ++++ + +title = "PostgreSQL与openGauss之关键字" + +date = "2020-12-17" + +tags = ["openGauss与postgresql对比"] + +archives = "2020-12" + +author = "高云龙" + +summary = "PostgreSQL与openGauss之关键字" + +img = "/zh/post/gaoyunlong/title/title.PNG" + +times = "16:40" + ++++ + +# PostgreSQL与openGauss之关键字 + +日常数据库运维的过程中可能对数据库关键字关注点并不是很高,但在程序开发的过程中,数据库对象建模要尽可能的避开数据库关键字的使用,否则在后续开发过程中需要用到各种转译的方法来将关键字转换为普通字符,会非常的麻烦。最近在openGauss上执行date函数后报语法错误,经查询openGauss是支持date函数的,但却用不了,真对这个问题,分别在PostgreSQL12.2数据库和openGauss(1.0.1)数据库进行问题复现并问题分析。 + +在openGauss执行结果如下: + +![](../figures/11.png) + +在PostgreSQL执行date函数结果如下: + +![](../figures/22.png) + +经调查发现是date关键字的问题。 + +在openGauss的关键字列表中,虽然不是保留关键字,但是不允许是函数或者类型。 + +![](../figures/33.png) + +在PostgreSQL的关键字列表中,是一个普通字符。 + +![](../figures/44.png) + +由此问题进行深入思考,对比PostgreSQL与openGauss数据库中哪些关键字做了差异化说明,避免在日常使用中再次遇到类似问题。 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
  

PostgreSQL

+

openGauss

+

DATE

+

-

+

非保留(不能是函数或类型)

+

IS

+

reserved (can be function or type)

+

保留

+

ISNULL

+

reserved (can be function or type)

+

非保留

+

LATERAL

+

reserved

+

-

+

MAXVALUE

+

non-reserved

+

保留

+

NUMBER

+

-

+

非保留(不能是函数或类型)

+

PROCEDURE

+

non-reserved

+

保留

+

TABLESAMPLE

+

reserved (can be function or type)

+

-

+

XMLNAMESPACES

+

non-reserved (cannot be function or type)

+

-

+

XMLTABLE

+

non-reserved (cannot be function or type)

+

-

+
+ +通过对比两个数据库的保留关键字,在openGauss中"date"和"number" 虽然不是保留关键字,但是不可用于函数或类型操作,"isnull"和"LATERAL"变为非保留关键字,"maxvalue"和"procedure"变为保留关键字,“TABLESAMPLE”、“XMLNAMESPACES"及"XMLTABLE”不再做限制。 + diff --git "a/content/zh/post/gaoyunlong/PostgreSQL\344\270\216openGauss\344\271\213\346\225\260\346\215\256\347\261\273\345\236\213.md" "b/content/zh/post/gaoyunlong/PostgreSQL\344\270\216openGauss\344\271\213\346\225\260\346\215\256\347\261\273\345\236\213.md" new file mode 100644 index 0000000000000000000000000000000000000000..23e3eb6f414a6119a0a49baccdf75e078c909c76 --- /dev/null +++ "b/content/zh/post/gaoyunlong/PostgreSQL\344\270\216openGauss\344\271\213\346\225\260\346\215\256\347\261\273\345\236\213.md" @@ -0,0 +1,528 @@ ++++ + +title = "PostgreSQL与openGauss之数据类型" + +date = "2020-12-17" + +tags = ["openGauss与postgresql对比"] + +archives = "2020-12" + +author = "高云龙" + +summary = "PostgreSQL与openGauss之数据类型" + +img = "/zh/post/gaoyunlong/title/title1.png" + +times = "18:00" + ++++ + +# PostgreSQL与openGauss之数据类型 + +openGauss是基于PostgreSQL 9.2.4 内核版本开发的,且openGauss的兼容性很强,包括兼容oracle、mysql、tidb及PostgreSQL,如果习惯了PostgreSQL的用法再来维护openGauss数据库,在日常维护使用过程中经常会出现不支持或者语法错误,现在整理一下两个数据库常用数据类型的差异,可快速在PostgreSQL 和 openGauss 两个数据库之间进行切换,减少出错的概率。 + +数据库对比版本如下: + +- PostgreSQL版本 12.2 +- openGauss 版本 1.0.1 + +## 数字类型 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
  

PostgreSQL

+

openGauss

+

存储尺寸

+

备注

+

tinyint

+

-

+

支持

+

1字节

+

0 ~ 255

+

smallint

+

支持

+

支持

+

2字节

+

-32,768 ~ +32,767

+

integer

+

支持

+

支持

+

4字节

+

-2,147,483,648 ~ +2,147,483,647

+

binary_integer

+
  

支持

+

-

+

integer别名

+

bigint

+

支持

+

支持

+

8字节

+

-9,223,372,036,854,775,808 ~ +9,223,372,036,854,775,807

+

decimal[(p[,s])]

+

支持

+

支持

+

可变字节

+

最高小数点前131072位,以及小数点后16383位

+

numeric[(p[,s])]

+

支持

+

支持

+

可变字节

+

最高小数点前131072位,以及小数点后16383位

+

number[(p[,s])]

+

-

+

支持

+

-

+

numeric别名

+

real

+

支持

+

支持

+

4字节

+

6位十进制数字精度

+

float4

+

-

+

支持

+

4字节

+

6位十进制数字精度

+

double precision

+

支持

+

支持

+

8字节

+

15位十进制数字精度

+

binary_double

+

-

+

支持

+

8字节

+

double precision别名

+

float8

+

-

+

支持

+

8字节

+

15位十进制数字精度

+

float[(p )]

+

-

+

支持

+

4字节或8字节

+

-

+

dec[(p,[s])]

+

-

+

支持

+

-

+

最高小数点前131072位,以及小数点后16383位

+

integer[(p,[s])]

+

-

+

支持

+

-

+

最高小数点前131072位,以及小数点后16383位

+

smallserial

+

支持

+

支持

+

2字节

+

1 ~ 32,767

+

serial

+

支持

+

支持

+

4字节

+

1 ~ 2,147,483,647

+

bigserial

+

支持

+

支持

+

8字节

+

1 ~ 9,223,372,036,854,775,807

+
+ +## 字符类型 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
  

PostgreSQL

+

openGauss

+

存储尺寸

+

备注

+

char(n)

+

支持

+

支持

+

pg中最大为1GB,og中最大为10MB

+

pg中n指字符数量,og中n指字节数量

+

nchar(n)

+

-

+

支持

+

最大为10MB

+

n指字节数量

+

varchar(n)

+

支持

+

支持

+

pg中最大为1GB,og中最大为10MB

+

pg中n指字符数量,og中n指字节数量

+

varchar2(n)

+

-

+

支持

+

最大为10MB

+

varchar(n)别名

+

nvarchar2(n)

+

-

+

支持

+

最大为10MB

+

n指字符数量

+

text

+

支持

+

支持

+

1GB - 1

+

-

+

clob

+

-

+

支持

+

1GB - 1

+

text别名

+
+ +## 时间日期类型 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
  

PostgreSQL

+

openGauss

+

存储尺寸

+

备注

+

timestamp[(p )][without time zone]

+

支持

+

支持

+

8字节

+

4713 BC - 294276 AD

+

timestamp[(p )][with time zone]

+

支持

+

支持

+

8字节

+

4713 BC - 294276 AD

+

date

+

支持

+

支持

+

4字节

+

4713 BC - 5874897 AD (og实际存储空间大小为8字节)

+

time[(p )][without time zone]

+

支持

+

支持

+

8字节

+

00:00:00 - 24:00:00

+

time[(p )][with time zone]

+

支持

+

支持

+

12字节

+

00:00:00+1459 - 24:00:00-1459

+

interval[fields][(p )]

+

支持

+

支持

+

16字节

+

-178000000年 - 178000000年

+

smalldatetime

+
  

支持

+

8字节

+

日期和时间,不带时区,精确到分钟,秒位大于等于30秒进一位

+

interval day(1) to second(p )

+
  

支持

+

16字节

+

-

+

reltime

+
  

支持

+

4字节

+

-

+
+ +## json类型 + + + + + + + + + + + + + + + + + + + + + + +
  

PostgreSQL

+

openGauss

+

存储尺寸

+

备注

+

json

+

支持

+

支持

+

-

+

-

+

jsonb

+

支持

+

-

+

-

+

-

+
+ +## 货币类型 + + + + + + + + + + + + + + + + +
  

PostgreSQL

+

openGauss

+

存储尺寸

+

备注

+

money

+

支持

+

支持

+

8字节

+

-92233720368547758.08到+92233720368547758.07

+
+ diff --git a/content/zh/post/gaoyunlong/figures/11.png b/content/zh/post/gaoyunlong/figures/11.png new file mode 100644 index 0000000000000000000000000000000000000000..3808d239194b282cef3b7171672e35cfd1cff484 Binary files /dev/null and b/content/zh/post/gaoyunlong/figures/11.png differ diff --git a/content/zh/post/gaoyunlong/figures/22.png b/content/zh/post/gaoyunlong/figures/22.png new file mode 100644 index 0000000000000000000000000000000000000000..09bf9a4bc9382dd8e78915c89811214b97a99e89 Binary files /dev/null and b/content/zh/post/gaoyunlong/figures/22.png differ diff --git a/content/zh/post/gaoyunlong/figures/33.png b/content/zh/post/gaoyunlong/figures/33.png new file mode 100644 index 0000000000000000000000000000000000000000..b45b3a8de0a5375e8cbae79c3ec1cf59f496c70e Binary files /dev/null and b/content/zh/post/gaoyunlong/figures/33.png differ diff --git a/content/zh/post/gaoyunlong/figures/44.png b/content/zh/post/gaoyunlong/figures/44.png new file mode 100644 index 0000000000000000000000000000000000000000..e96b0daf12bf11ce7ad321734bfdffb88d8c3ea8 Binary files /dev/null and b/content/zh/post/gaoyunlong/figures/44.png differ