4

我想将一个文件重要到我的 Postgresql 系统(特别是 RedShift)中。我发现了一个允许导入 gzip 文件的副本的争论。但是我试图在我的系统中包含的数据的提供者只生成 .zip 格式的数据。任何用于打开 .zip 的内置 postgres 命令?

4

4 回答 4

3

从 Postgres 内部:

COPY table_name FROM PROGRAM 'unzip -p input.csv.zip' DELIMITER ',';

从手册页unzip -p

-p     extract files to pipe (stdout).  Nothing but the file data is sent to stdout, and the files are always extracted  in  binary
       format, just as they are stored (no conversions).
于 2017-09-14T21:08:15.083 回答
2

你能做类似的事情吗

unzip -c myfile.zip | gzip myfile.gz

如果你有足够的文件,很容易实现自动化。

于 2013-07-20T16:51:03.323 回答
1

这可能仅在从 S3 加载 redshift 时有效,但实际上您可以在将数据复制到 redshift 表时仅包含“gzip”标志,如下所述

如果我的 s3 存储桶包含 gzip 压缩的 .csv,则此格式适用于我。

copy <table> from 's3://mybucket/<foldername> '<aws-auth-args>' delimiter ',' gzip;
于 2016-12-28T16:57:25.803 回答
0

unzip -c /path/to/.zip | psql -U user

“用户”必须具有超级用户权限,否则您将获得

ERROR:  must be superuser to COPY to or from a file

要了解有关此的更多信息,请参阅

https://www.postgresql.org/docs/8.0/static/backup.html

基本上这个命令用于处理大型数据库

于 2016-11-07T19:14:06.277 回答