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

openGauss每日一练第12天-数据类型

天道酬勤 2021-12-13
362

omm=#
omm=# create type wwww as (col1 int,col2 varchar(100));
CREATE TYPE
omm=# alter type wwww rename to www;
ALTER TYPE
omm=# \d
List of relations
Schema | Name | Type | Owner | Storage
--------+------------+-------+-------+----------------------------------
public | t1_compfoo | table | omm | {orientation=row,compression=no}
(1 row)

omm=# \d www
Composite type "public.www"
Column | Type | Modifiers
--------+------------------------+-----------
col1 | integer |
col2 | character varying(100) |

omm=# alter type www add attribute col3 int;
ALTER TYPE
omm=# \d www
Composite type "public.www"
Column | Type | Modifiers
--------+------------------------+-----------
col1 | integer |
col2 | character varying(100) |
col3 | integer |

omm=# alter type www drop attribute col2;
ALTER TYPE
omm=# \d www
col3 | integer |

omm=# Composite type "public.www"
Column | Type | Modifiers
--------+---------+-----------
col1 | integer |
omm=#
create type ww_status as enum('create','modify','closed');
CREATE TYPE
omm=# select * from pg_enum;
enumtypid | enumsortorder | enumlabel
-----------+---------------+-----------
16446 | 1 | create
16446 | 2 | modify
16446 | 3 | closed
(3 rows)

omm=# \d ww_status;
Did not find any relation named "ww_status".
omm=# alter type ww_status add value if not exists 'regress' before 'closed';
omm=# ALTER TYPE

omm=# select * from pg_enum;
enumtypid | enumsortorder | enumlabel
-----------+---------------+-----------
16446 | 1 | create
16446 | 2 | modify
16446 | 3 | closed
16446 | 2.5 | regress
(4 rows)

omm=# alter type ww_status rename value 'create' to 'create_new';
ALTER TYPE
omm=# select * from pg_enum;
enumtypid | enumsortorder | enumlabel
-----------+---------------+------------
16446 | 2 | modify
16446 | 3 | closed
16446 | 2.5 | regress
16446 | 1 | create_new
omm=# (4 rows)


omm=# create table ww_tb(id int,name www);
CREATE TABLE
omm=# \d www
Composite type "public.www"
Column | Type | Modifiers
--------+---------+-----------
col1 | integer |
col3 | integer |

omm=# insert into ww_tb(1,(1,1));
ERROR: syntax error at or near "1"
LINE 1: insert into ww_tb(1,(1,1));
^
omm=# insert into ww_tb values(1,(1,1));
INSERT 0 1
omm=# select * from ww_tb;
id | name
----+-------
1 | (1,1)
(1 row)

omm=# select (b).col3 from ww_tb;
ERROR: column "b" does not exist
LINE 1: select (b).col3 from ww_tb;
^
CONTEXT: referenced column: col3
omm=# select (name).col3 from ww_tb;
col3
------
1
(1 row)

omm=# drop table ww_tb;
DROP TABLE
omm=# drop type www;
omm=# DROP TYPE
drop type ww_status;
DROP TYPE
omm=#
omm=# 

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

评论