postgresql 如何将压缩文件导入Postgres表

omhiaaxx  于 2022-12-12  发布在  PostgreSQL
关注(0)|答案(4)|浏览(189)

我想把一个文件导入到我的Postgresql系统(特别是RedShift)。我发现了一个允许导入gzip文件的复制参数。但是我试图在我的系统中包含的数据的提供程序只生成了一个. zip格式的数据。是否有任何内置的postgres命令可以打开一个.zip文件?

lp0sw83n

lp0sw83n1#

From within Postgres:

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

From the man page for 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).
dxxyhpgq

dxxyhpgq2#

你能不能做点
unzip -c myfile.zip | gzip myfile.gz
如果您有足够的文件,则可以轻松实现自动化。

ebdffaop

ebdffaop3#

This might only work when loading redshift from S3, but you can actually just include a "gzip" flag when copying data to redshift tables, as described here :
This is the format that works for me if my s3 bucket contains a gzipped .csv.

copy <table> from 's3://mybucket/<foldername> '<aws-auth-args>' delimiter ',' gzip;
hsgswve4

hsgswve44#

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
基本上,此命令用于处理大型数据库

相关问题