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

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

天道酬勤 2021-12-13
486

omm=# create database ww;
CREATE DATABASE
omm=# \c ww'
unterminated quoted string
Non-SSL connection (SSL connection is recommended when requiring high-security)
You are now connected to database "omm" as user "omm".
omm=# \c ww;
Non-SSL connection (SSL connection is recommended when requiring high-security)
You are now connected to database "ww" as user "omm".
ww=# \d
No relations found.
ww=# create table t1(a int,b varchar(10),c varchar(10));
CREATE TABLE
ww=# \d
List of relations
Schema | Name | Type | Owner | Storage
--------+------+-------+-------+----------------------------------
public | t1 | table | omm | {orientation=row,compression=no}
(1 row)

ww=# insert into t1 values(1);
INSERT 0 1
ww=# insert into t1 values(1,'a');
INSERT 0 1
ww=# select * from t1;
a | b | c
---+---+---
1 | |
1 | a |
(2 rows)

ww=# insert into t1 values;
ERROR: syntax error at or near ";"
LINE 1: insert into t1 values;
^
ww=# insert into t1 default values;
INSERT 0 1
ww=# select * from t1;
a | b | c
---+---+---
1 | |
1 | a |
| |
(3 rows)

ww=# create table t2 (a int,b varchar(10),c varchar(10));
ww=# CREATE TABLE

ww=# \d
List of relations
Schema | Name | Type | Owner | Storage
--------+------+-------+-------+----------------------------------
public | t1 | table | omm | {orientation=row,compression=no}
public | t2 | table | omm | {orientation=row,compression=no}
(2 rows)

ww=# insert into t2 select * from t1;
INSERT 0 3
ww=#
ww=# create table t3(a int,b varchar(10));
CREATE TABLE
ww=# create table t(a int,bww=#

ww=#
ww=# create table t4(a int,b varchar(10));
CREATE TABLE
ww=# insert into t3 values(1,'a');
INSERT 0 1
ww=# insert into t3 values(,'a');2,'');b');
INSERT 0 1
ww=# insert into t3 values(,'b');3,'');c');
INSERT 0 1
ww=#
ww=#
ww=#
ww=# select * from t3;
a | b
---+---
1 | a
2 | b
3 | c
(3 rows)

ww=# insert into t4(1,'aa'),(2,'bb'),(3,'c');
ERROR: syntax error at or near "1"
LINE 1: insert into t4(1,'aa'),(2,'bb'),(3,'c');
^
ww=# insert into t4 values(1,'aa'),(2,'bb'),(3,'c');
INSERT 0 3
ww=# select * from t4;
a | b
---+----
1 | aa
2 | bb
3 | c
(3 rows)

ww=# merge into t4 using t3 on t4.a = t3.a when matched then update set t4.b = t3.b when not matched then insert values(t3.a,t3.b);
MERGE 3
ww=# select * from t4;
a | b
---+---
1 | a
2 | b
3 | c
(3 rows)

ww=# copy t3 to stdout ;
1 a
2 b
3 c
ww=# copy t3 to '/home/omm/t3.dat';
COPY 3
ww=# create table t5(a int,b varchar(10));
CREATE TABLE
ww=# copy t5 from '/home/omm/t3.dat';
COPY 3
ww=# select * from t5;
a | b
---+---
1 | a
2 | b
3 | c
(3 rows)

ww=# drop table t3;
DROP TABLE
ww=# drop table t;4;
DROP TABLE
ww=# drop table t;5;
DROP TABLE
ww=#
ww=# \d
List of relations
Schema | Name | Type | Owner | Storage
--------+------+-------+-------+----------------------------------
public | t1 | table | omm | {orientation=row,compression=no}
public | t2 | table | omm | {orientation=row,compression=no}
(2 rows)

ww=# drop table t1;
DROP TABLE
ww=# drop table t2;
DROP TABLE
ww=# 

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

评论