I\'ve been using the psql Postgres terminal to import CSV files into tables using the following
COPY tbname FROM
\'/tmp/the_file.csv\'
delimiter \'|\' csv;
<
The most flexible way is to use a shell HERE document, which allows you to use shell variables inside your query, even inside (double or single) quotes:
#!/bin/sh
THE_USER=moi
THE_DB=stuff
THE_TABLE=personnel
PSQL=/opt/postgresql/bin/psql
THE_DIR=/tmp
THE_FILE=the_file.csv
${PSQL} -U ${THE_USER} ${THE_DB} <