Postgres COPY FROM csv file- No such file or directory

后端 未结 5 830
失恋的感觉
失恋的感觉 2021-02-04 01:34

I\'m trying to import a (rather large) .txt file into a table geonames in PostgreSQL 9.1. I\'m in the /~ directory of my server, with a file named US.txt placed in that director

5条回答
  •  你的背包
    2021-02-04 01:41

    if you're running your COPY command from a script, you can have a step in the script that creates the COPY command with the correct absolute path.

    MYPWD=$(pwd)
    echo "COPY geonames FROM '$MYPWD/US.txt', DELIMITER E'\t';"
    MYPWD=
    

    you can then run this portion into a file and execute it

    ./step_to_create_COPY_with_abs_path.sh >COPY_abs_path.sql
    psql -f COPY_abs_path.sql -d your_db_name
    

提交回复
热议问题