oracle copy与postgresql copy(二)
PY { table_name [ ( column [, ...] ) ] | ( query ) }
TO { 'filename' | STDOUT }
[ [ WITH ] ( option [, ...] ) ]
where option can be one of:
FORMAT format_name
OIDS [ boolean ]
DELIMITER 'delimiter_character'
NULL 'null_string'
HEADER [ boolean ]
QUOTE 'quote_character'
ESCAPE 'escape_character'
FORCE_QUOTE { ( column [, ...] ) | * }
FORCE_NOT_NULL ( column [, ...] ) |
ENCODING 'encoding_name'
语法也是很简明的,介绍几个常用的选项
DELIMITER :指定分隔符
HEADER:声明文件包含一个头标识,包含字段名称
postgres=# copy t1 to '/home/postgres/t1.sql';
COPY 5
postgres=# copy t1 from '/home/postgres/t1.sql';
COPY 5
postgres=# select count(*) from t1;
count
-------
10
(1 row)
可以看到这里多了5行
postgres=# copy shoelace_log to '/home/postgres/shoelace_log.sql' DELIMITER ':';
1:apple
导出为CVS格式:
postgres=#copy t1 to '/home/postgres/t1.csv' csv header;
这里with写可不写
指定需要导出的列:
postgres=#copy t1(a,b) to '/home/postgres/t1.csv' with DELIMITER ':' csv header;