#opengauss的第13天
1.创建表1并在表中插入数据,分别指定字段和整行为缺省值
omm=# create table t1 (col1 int,col2 char(40),col3 char(40));
CREATE TABLE
omm=# insert into t1 values(1,‘hhh’,‘aabbcc’);
INSERT 0 1
omm=# insert into t1 values(1,‘hello world’);
INSERT 0 1
omm=# insert into t1 values(10,‘database’,default);
INSERT 0 1
omm=# select * from t1;
1 | hhh | aabbcc
1 | hello world |
10 | database |
(3 rows)
omm=# col1 | col2 | col3
------±-----------------------------------------±-----------------------------------------
select * from t1;
col1 | col2 | col3
------±-----------------------------------------±-----------------------------------------
1 | hhh | aabbcc
1 | hello world |
10 | database |
(3 rows)
omm=# insert into t1 default values;
INSERT 0 1
omm=# select * from t1;
col1 | col2 | col3
------±-----------------------------------------±-----------------------------------------
1 | hhh | aabbcc
1 | hello world |
10 | database |
| |
2.创建表2并将表1的数据全部导入表2中
omm=# create table t2 as select * from t1;
INSERT 0 4
omm=# select * from t2;
col1 | col2 | col3
------±-----------------------------------------±-----------------------------------------
1 | hhh | aabbcc
1 | hello world |
10 | database |
| |
3.创建表3和表4,并合并两个表的数据到表3
omm=# create table t3 (id bigint,clo1 char(40));
CREATE TABLE
omm=# insert into t3 select id,md5(random()::text) from generate_series(1,1000) as id;
INSERT 0 1000
omm=# create table t4 as select * from t3;
omm=# INSERT 0 1000
omm=#insert into t3 select * from t4;
INSERT 0 1000
omm= select count(*) from t3;
count
2000
(1 row)
omm=# select count(*) from t4;
omm=# count
1000
4.将表3的数据输出到文件,再将文件中的数据导入到表5
omm=# copy t3 to ‘/home/omm/t3.dat’;
COPY 2000
^
omm=# create table t5 (like t3 including all);
CREATE TABLE
omm=# copy t5 from ‘/home/omm/t3.dat’;
COPY 2000
omm=# select count(*) from t5;
omm=# count
2000