score:3

on_error_stop will not work with the -c option.

also, the $(...) surronding the psql look wrong — do you want to execute the output as a command?

finally, you forgot a backslash after the -l option

try using a “here document”:

psql \
  -x \
  $postgres_connection_string \
  -w \
  -b \
  -l ./output.txt \
  -a \
  -q \
  --set on_error_stop=on \
  -t <<eof
\copy mytable(...) from '$input_file' csv header
eof

echo "import is done"

Related Query

More Query from same tag