在线精品99_中国九九盗摄偷拍偷看_91免费版在线观看_91.app_91高清视频在线_99热最新网站

怎么使用PostgreSQL中的COPY命令

91次阅读
没有评论

共计 3434 个字符,预计需要花费 9 分钟才能阅读完成。

这篇文章主要讲解了“怎么使用 PostgreSQL 中的 COPY 命令”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着丸趣 TV 小编的思路慢慢深入,一起来研究和学习“怎么使用 PostgreSQL 中的 COPY 命令”吧!

Copy 命令在 PG 12 有所增强, 在 COPY FROM 时可添加 WHERE 条件过滤.

PG 11
Copy 命令

testdb=# \help copy
Command: COPY
Description: copy data between a file and a table
Syntax:
COPY table_name [ ( column_name [, ...] ) ]
 FROM {  filename  | PROGRAM  command  | STDIN }
 [ [ WITH ] ( option [, ...] ) ]
COPY { table_name [ ( column_name [, ...] ) ] | ( query ) }
 TO {  filename  | PROGRAM  command  | STDOUT }
 [ [ WITH ] ( option [, ...] ) ]
where option can be one of:
 FORMAT format_name
 OIDS [ boolean ]
 FREEZE [ boolean ]
 DELIMITER  delimiter_character 
 NULL  null_string 
 HEADER [ boolean ]
 QUOTE  quote_character 
 ESCAPE  escape_character 
 FORCE_QUOTE { ( column_name [, ...] ) | * }
 FORCE_NOT_NULL ( column_name [, ...] )
 FORCE_NULL ( column_name [, ...] )
 ENCODING  encoding_name

简单使用

testdb=# drop table if exists t_copy;
DROP TABLE
testdb=# CREATE TABLE t_copy(id int,c1 varchar(20));
CREATE TABLE
testdb=# insert into t_copy SELECT x, c1- ||x FROM generate_series(1, 1000) AS x;
INSERT 0 1000
testdb=# 
testdb=# COPY t_copy TO  /tmp/data/t_copy.txt  with DELIMITER  | 
COPY 1000
testdb=# drop table if exists t_import;
DROP TABLE
testdb=# CREATE TABLE t_import(id int,c1 varchar(20));
CREATE TABLE
testdb=# COPY t_import FROM  /tmp/data/t_copy.txt  with DELIMITER  | 
COPY 1000
testdb=# select * from t_import limit 10;
 id | c1 
----+-------
 1 | c1-1
 2 | c1-2
 3 | c1-3
 4 | c1-4
 5 | c1-5
 6 | c1-6
 7 | c1-7
 8 | c1-8
 9 | c1-9
 10 | c1-10
(10 rows)

不支持 WHERE 条件过滤

testdb=# COPY t_import FROM  /tmp/data/t_copy.txt  with DELIMITER  |  where id   5;
ERROR: syntax error at or near  where 
LINE 1: ...t FROM  /tmp/data/t_copy.txt  with DELIMITER  |  where id  ...

PG 12
COPY 命令语法

[local]:5432 pg12@testdb=# \help copy
Command: COPY
Description: copy data between a file and a table
Syntax:
COPY table_name [ ( column_name [, ...] ) ]
 FROM {  filename  | PROGRAM  command  | STDIN }
 [ [ WITH ] ( option [, ...] ) ]
 [ WHERE condition ]
COPY { table_name [ ( column_name [, ...] ) ] | ( query ) }
 TO {  filename  | PROGRAM  command  | STDOUT }
 [ [ WITH ] ( option [, ...] ) ]
where option can be one of:
 FORMAT format_name
 FREEZE [ boolean ]
 DELIMITER  delimiter_character 
 NULL  null_string 
 HEADER [ boolean ]
 QUOTE  quote_character 
 ESCAPE  escape_character 
 FORCE_QUOTE { ( column_name [, ...] ) | * }
 FORCE_NOT_NULL ( column_name [, ...] )
 FORCE_NULL ( column_name [, ...] )
 ENCODING  encoding_name 
URL: https://www.postgresql.org/docs/12/sql-copy.html

支持 WHERE 条件过滤

[local]:5432 pg12@testdb=# drop table if exists t_copy;
DROP TABLE
Time: 50.327 ms
[local]:5432 pg12@testdb=# CREATE TABLE t_copy(id int,c1 varchar(20));
CREATE TABLE
Time: 5.038 ms
[local]:5432 pg12@testdb=# insert into t_copy SELECT x, c1- ||x FROM generate_series(1, 1000) AS x;
INSERT 0 1000
Time: 16.422 ms
[local]:5432 pg12@testdb=# 
[local]:5432 pg12@testdb=# COPY t_copy TO  /tmp/data/t_copy.txt  with DELIMITER  | 
COPY 1000
Time: 4.795 ms
[local]:5432 pg12@testdb=# drop table if exists t_import;
DROP TABLE
Time: 4.798 ms
[local]:5432 pg12@testdb=# CREATE TABLE t_import(id int,c1 varchar(20));
CREATE TABLE
Time: 2.462 ms
[local]:5432 pg12@testdb=# COPY t_import FROM  /tmp/data/t_copy.txt  with DELIMITER  |  WHERE id   5;
COPY 4
Time: 4.842 ms
[local]:5432 pg12@testdb=# select * from t_import;
 id | c1 
----+------
 1 | c1-1
 2 | c1-2
 3 | c1-3
 4 | c1-4
(4 rows)
Time: 6.103 ms

感谢各位的阅读,以上就是“怎么使用 PostgreSQL 中的 COPY 命令”的内容了,经过本文的学习后,相信大家对怎么使用 PostgreSQL 中的 COPY 命令这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是丸趣 TV,丸趣 TV 小编将为大家推送更多相关知识点的文章,欢迎关注!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-26发表,共计3434字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)
主站蜘蛛池模板: a级淫片 | 日本一级淫片漂亮的老师一 | 秋霞无码一区二区 | 国产精品久久久久久无码 | 粉嫩少妇内射浓精videos | 亚洲伊人成综合网 | 欧美色惰aⅴ | 午夜国产小视频 | 中文字幕欧美视频 | 免费黄色电影在线观看 | 免费午夜视频在线观看 | 欧美日韩国产精品va | 欧美激情一区二区三区在线 | 亚洲av综合a色av中文 | 午夜无码国产理论在线 | 思思99精品国产自在现线 | 国产高清美女一级毛片久久 | 少妇人妻av毛片在线看 | 嫩草在线播放 | 亚洲日韩国产一区二区三区 | 韩国精品一区视频在线播放 | 精品国产一区二区三区久久影院 | 精品动漫中文字幕一区二区三区 | 青草内射中出高潮 | 久草在线观看首页 | 99久久国产综合精品成人影院 | 亚洲欧美另类激情综合区蜜芽 | 色综合久久久久综合一本到桃花网 | 亚洲精品国产第一区二区图片 | 亚洲综合一区国产精品 | 天天影视色香欲综合网 西瓜影音 | 亚洲精品国产经典一区二区 | 一边摸一边抽搐一进一出口述 | 免费的黄色片视频 | 中文字幕1区2区 | 久久人妻内射无码一区三区 | 男人的蛋xx进了女人的屁股里 | 久久精品视频国产 | 成人黄网18免费观看的网站 | 午夜在线观看网站 | 亚洲综合伦理 |