Copy data from local file with Postgres and psql

Posted: February 8th, 2011
By:
Tommy Unger

It was surprisingly hard to find a functional, working example of copying data from a file not based on the server into a PostgreSQL database.

cat file.txt | psql -c “COPY table_name FROM STDIN” -U username database_name

And don’t forget the handy trick for disabling the password prompt in psotgres.

A few helpful search terms:

  • Copy file into Postgres from local filesystem
  • Copy local file into Postgres from command line
  • Using psql to copy file into Postgres database from file system
#000000
#1d3147
#415973
#9dacb9
#4c3724
#897661
#d1c8c0
#ffffff