今天学习openGauss定义数据类型,以下是作业和心得:
1. 连接openGauss
su - omm gsql -r
2. 创建一个复合类型,重命名复合类型,为复合类型增加属性、删除属性
create type comf as (f1 int, f2 text);
create table t1_comf(a int, b comf);
\d comf
alter type comf rename to comf1;
\d comf1
alter type comf1 add attribute f3 int;
\d comf1
alter type comf1 drop attribute f1;
\d comf1
\

3. 创建一个枚举类型,新增标签值,重命名标签值
create type bug as enum ('create', 'modify', 'closed');
alter type bug add value if not exists 'regress' before 'closed';
alter type bug rename value 'create' to 'new';
select * from pg_enum;
\
**4. 使用新创建的类型创建表**
```sql
create table t1_comf1(c int, d comf1);
select * from t1_comf1;
\
5. 删除类型
drop type comf1 cascade;
drop type bug;
\

通过学习和作业,巩固了openGauss定义数据类型的知识。add attribute,drop attribute和alter attribute选项可以组合成一个列表同时处理。
比如,在一条命令中同时增加几个属性或是更改几个属性的类型是可以实现的。特别注意:要修改一个类型的模式,必须在新模式上用户create权限。要修改所有者,必须要新的所有角色的直接或间接成员,并且该成员必须在此类型的模式上有create权限。限制强制修改所有者不会删除和重建类型,但是系统管理员可以修改任意类型的所有权。要增加一个属性或是修改一个属性的类型,必须有该类型的usage权限。
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




