暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

openGauss每日一练第12天|学习openGauss定义的数据类型

原创 赵敬星 2021-12-12
516

坚持学习openGauss数据库,坚持每天打卡。第十二天学习openGauss定义的数据类型。

连接opengauss

root@modb:~# su - omm omm@modb:~$ gsql -r gsql ((opengauss 2.0.0 build 78689da9) compiled at 2021-03-31 21:03:52 commit 0 last mr ) non-ssl connection (ssl connection is recommended when requiring high-security) type "help" for help. omm=#

1.创建一个复合类型,重命名复合类型,为复合类型增加属性、删除属性

--创建复合类型 omm=# create type fhtype as (f1 int, f2 text); CREATE TYPE --重命名复合类型 omm=# alter type fhtype rename to fhtype1; ALTER TYPE --复合类型增加属性 omm=# alter type fhtype1 add attribute f3 int; ALTER TYPE --删除复合类型属性 omm=# alter type fhtype1 drop attribute f3; ALTER TYPE

2.创建一个枚举类型,新增标签值,重命名标签值

--创建枚举类型 omm=# create type mjtype as enum ('create', 'modify', 'closed'); CREATE TYPE --新增标签值 omm=# alter type mjtype add value if not exists 'regress' before 'closed'; ALTER TYPE --重命名标签值 omm=# alter type mjtype rename value 'create' to 'new'; ALTER TYPE

3.使用新创建的类型创建表

omm=# create table tab_fhtype1(a int, b fhtype1); CREATE TABLE omm=# insert into tab_fhtype1 values(1,(1,'demo')); INSERT 0 1 omm=# select a,(b).f1,(b).f2 from tab_fhtype1; a | f1 | f2 ---+----+------ 1 | 1 | demo (1 row)

4.删除类型

omm=# drop table tab_fhtype1; DROP TABLE --也可以加上cascade级联删除类型 omm=# drop type fhtype1; DROP TYPE omm=# drop type mjtype; DROP TYPE

通过学习openGauss定义的数据类型,加上作业里面创建复合类型,重命名复合类型,复合类型增加属性,创建枚举类型,枚举类型增加标签值,重命名标签值,使用新创建的类型创建表,删除类型等操作,更加理解openGauss定义的数据类型。

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

文章被以下合辑收录

评论