Importing zipped CSV file into PostgreSQL

后端 未结 3 485
忘了有多久
忘了有多久 2020-12-06 00:46

I have a big compressed csv file (25gb) and I want to import it into PostgreSQL 9.5 version. Is there any fast way to import zip or qzip file into postgres without extractin

3条回答
  •  情书的邮戳
    2020-12-06 01:47

    example how to do it with zcat and pipe:

    -bash-4.2$ psql -p 5555 t -c "copy tp to '/tmp/tp.csv';"
    COPY 1
    -bash-4.2$ gzip /tmp/tp.csv
    -bash-4.2$ zcat /tmp/tp.csv.gz | psql -p 5555 t -c "copy tp from stdin;"
    COPY 1
    -bash-4.2$ psql -p 5555 t -c "select count(*) from tp"
     count
    -------
         2
    (1 row)
    

    also from 9.3 release you can:

    psql -p 5555 t -c "copy tp from program 'zcat /tmp/tp.csv.gz';"
    

    without pipe at all

提交回复
热议问题