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

openGauss每日一练第 13 天

原创 刘志亮 2021-12-13
384

opengauss 学习第十三天

学习openGauss导入数据


1.创建表1并在表中插入数据,分别指定字段和整行为缺省值

CREATE TABLE table_t1
(
r_reason_sk integer,
r_reason_id character(16),
r_reason_desc character(100)
);
insert into table_t1 values(1, 'AAAAAAAABAAAAAAA', 'reason1');

insert into table_t1 values(1, 'AAAAAAAABAAAAAAA', DEFAULT);

insert into table_t1 DEFAULT VALUES;




2.创建表2并将表1的数据全部导入表2中

CREATE TABLE table_t2
(
r_reason_sk integer,
r_reason_id character(16),
r_reason_desc character(100)
);
INSERT INTO table_t2 SELECT * FROM table_t1;



3.创建表3和表4,并合并两个表的数据到表3

创建表3

CREATE TABLE table_t3
( product_id INTEGER,
product_name VARCHAR2(60),
category VARCHAR2(60)
);
INSERT INTO table_t3 VALUES
(1502, 'olympus camera', 'electrncs'),
(1601, 'lamaze', 'toys'),
(1666, 'harry potter', 'toys'),
(1700, 'wait interface', 'books');


创建表4

CREATE TABLE table_t4
( product_id INTEGER,
product_name VARCHAR2(60),
category VARCHAR2(60)
);
INSERT INTO table_t4 VALUES
(1501, 'vivitar 35mm', 'electrncs'),
(1502, 'olympus ', 'electrncs'),
(1600, 'play gym', 'toys'),
(1601, 'lamaze', 'toys'),
(1666, 'harry potter', 'dvd');


合并两个表的数据到表3

MERGE INTO table_t3 np
USING table_t4 p
ON (np.product_id = p.product_id )
WHEN MATCHED THEN
UPDATE SET np.product_name = p.product_name, np.category = p.category
WHEN NOT MATCHED THEN
INSERT VALUES (p.product_id, p.product_name, p.category) ;


4.将表3的数据输出到文件,再将文件中的数据导入到表5

将表3数据输出到文件t3.dat

copy table_t3 to '/home/omm/t3.dat';


创建表5,将文件数据导入到表5

CREATE TABLE table_t5 (LIKE table_t3 );
copy table_t5  from '/home/omm/t3.dat';


第十三天学习openGauss 数据导入的多种方式。

每天进步一点点,期待明天加油!

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

评论