PostgreSQL数据导出导入COPY

[postgres@DELL-R720 bin]$ ./psql -p 6432
psql (9.4.5)
Type "help" for help.

postgres=# 
postgres=# \h 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'

postgres=# \d+
List of relations
Schema | Name | Type | Owner | Size | Description 
--------+------------+-------+--------------+----------+-------------
public | customer | table | benchmarksql | 1772 MB | 
public | district | table | benchmarksql | 152 kB | 
public | history | table | benchmarksql | 250 MB | 
public | item | table | benchmarksql | 10184 kB | 
public | new_order | table | benchmarksql | 38 MB | 
public | oorder | table | benchmarksql | 198 MB | 
public | order_line | table | benchmarksql | 3000 MB | 
public | stock | table | benchmarksql | 3392 MB | 
public | warehouse | table | benchmarksql | 40 kB | 
(9 rows)

postgres=# copy stock to '/tmp/stock.sql';
COPY 10000000
postgres=# truncate stock ;
TRUNCATE TABLE
postgres=# \d+
List of relations
Schema | Name | Type | Owner | Size | Description 
--------+------------+-------+--------------+----------+-------------
public | customer | table | benchmarksql | 1772 MB | 
public | district | table | benchmarksql | 152 kB | 
public | history | table | benchmarksql | 250 MB | 
public | item | table | benchmarksql | 10184 kB | 
public | new_order | table | benchmarksql | 38 MB | 
public | oorder | table | benchmarksql | 198 MB | 
public | order_line | table | benchmarksql | 3000 MB | 
public | stock | table | benchmarksql | 0 bytes | 
public | warehouse | table | benchmarksql | 40 kB | 
(9 rows)

postgres=# copy stock from /tmp/stock.sql ;
ERROR: syntax error at or near "/" at character 18
STATEMENT: copy stock from /tmp/stock.sql ;
ERROR: syntax error at or near "/"
LINE 1: copy stock from /tmp/stock.sql ;
^
postgres=# copy stock from '/tmp/stock.sql' ;
COPY 10000000
postgres=# \d+
List of relations
Schema | Name | Type | Owner | Size | Description 
--------+------------+-------+--------------+----------+-------------
public | customer | table | benchmarksql | 1772 MB | 
public | district | table | benchmarksql | 152 kB | 
public | history | table | benchmarksql | 250 MB | 
public | item | table | benchmarksql | 10184 kB | 
public | new_order | table | benchmarksql | 38 MB | 
public | oorder | table | benchmarksql | 198 MB | 
public | order_line | table | benchmarksql | 3000 MB | 
public | stock | table | benchmarksql | 3392 MB | 
public | warehouse | table | benchmarksql | 40 kB | 
(9 rows)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

行动派大鹏

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值