0

I am trying to use a psql loop to load a directory of csv files into an AWS RDS Postgres database.

This StackExchange post answers how to do so locally and the following code works with a single file:

PGPASSWORD='MyPassword' psql -h my-rds.instance.us-east-1.rds.amazonaws.com -U user -d mydatabase -c '\COPY dbo.input_table FROM ''MySingleFile.csv'' CSV HEADER'

but I can't "combine" the two features. This code is the closest I can get but I get the following error for each file that is identified by the ls *.csv command:

for x in $(ls *.csv); 
do PGPASSWORD='MyPassword' psql -h my-rds.instance.us-east-1.rds.amazonaws.com -U user -d mydatabase -c "\COPY dbo.input_table FROM ''MySingleFile.csv'' CSV HEADER"; done

ERROR:  conflicting or redundant options
...
ERROR:  conflicting or redundant options
Frank B.
  • 1,813
  • 5
  • 24
  • 44
  • something like `for filename in *.csv ; do` ? and then `dostuff $filename` – Jim Jones Feb 19 '18 at 15:09
  • sorry but no, same error message – Frank B. Feb 19 '18 at 15:18
  • Strange. I have loop here working like this `for filename in *.xml* ; do for ((i=0; i<=3; i++)); do perl -i -pe 's/\n/\\n/g' $filename done done` – Jim Jones Feb 19 '18 at 15:20
  • Ya, sorry, not sure what's different about my code. – Frank B. Feb 19 '18 at 15:28
  • I'm not familiar with the syntax you used in the command inside the loop. In case the loop isn't the issue, consider removing this `PGPASSWORD='MyPassword'` and placing a password inside the `.pgpass` file. Good luck man! https://stackoverflow.com/questions/6405127/how-do-i-specify-a-password-to-psql-non-interactively – Jim Jones Feb 19 '18 at 15:37

0 Answers0