自己安装的openGauss环境
启动openGauss
gs_ctl -D /gauss/data/db1/ start
登录openGauss
gsql -d postgres -p 26000 -r
1.创建一个复合类型,重命名复合类型,为复合类型增加属性、删除属性
CREATE TYPE compfoo_hc1 AS (f1 int, f2 text);
alter TYPE compfoo_hc1 rename to compfoo_hc2;
ALTER TYPE compfoo_hc2 ADD ATTRIBUTE f3 int;
\d+ compfoo_hc2
ALTER TYPE compfoo_hc2 drop ATTRIBUTE f1;
\d+ compfoo_hc2

2.创建一个枚举类型,新增标签值,重命名标签值
CREATE TYPE test_type1 AS ENUM (‘create’, ‘modify’, ‘closed’);
ALTER TYPE test_type1 ADD VALUE IF NOT EXISTS ‘regress’ BEFORE ‘closed’;
ALTER TYPE test_type1 RENAME VALUE ‘create’ TO ‘new’;
select * from pg_enum;

3.使用新创建的类型创建表
CREATE TABLE t1_hc(a test_type1, b compfoo_hc2);
INSERT INTO t1_hc values(‘new’,((‘demo’),3));
SELECT * FROM t1_hc;

4.删除类型
drop table t1_hc;
drop type compfoo_hc2;
drop type test_type1;

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




