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