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

openGauss每日一练第13天 (导入数据)

原创 2021-12-13
276

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

postgres=# create table table1(id int, name char(20)); postgres=# insert INTO table1 values (1, default); postgres=# insert into table1 default values ;

image.png

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

postgres=# create table table2(id int, name char(20)); postgres=# insert into table2 select * from table1;

image.png

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

postgres=# create table table3(id int, name char(20)); postgres=# insert into table3 values(2, 'tom'),(3, 'jack'); postgres=# create table table4(id int, name char(20)); postgres=# insert into table3 values(2, 'tom'),(4, 'mary'); postgres=# merge into table4 t4 using table3 t3 on (t3.id = t4.id) postgres-# when matched then postgres-# update set t4.name = t3.name postgres-# when not matched then postgres-# insert values (t3.id, t3.name);

image.png

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

postgres=# copy table3 to '/home/omm/table0.dat'; postgres=# create table table5(like table3); postgres=# copy table5 from '/home/omm/table0.dat';

image.png

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

评论