1

my postgres version is 12.4 , I'm loading multiple csv files into single table, The problem here is every time firing below command is not good ,any other alternative (or) suggestions are there?

COPY testemail FROM '/md-data/vamshi/s3data/test_Hash_2021.csv' WITH (FORMAT csv);
COPY testmail FROM '/md-data/vamshi/s3data/test_Hash_2025.csv' WITH (FORMAT csv);
COPY testmail FROM '/md-data/vamshi/s3data/test_Hash_2026.csv' WITH (FORMAT csv);
 ..............etc 

and below command also i tried, but its not working,

 COPY testemail FROM '/md-data/vamshi/s3data/t*.csv' WITH (FORMAT csv);
2
  • 1
    Why do you think the first one is "not good"? copy doesn't support wildcards. If you want to automate this, write a shell script that iterates over the files and runs COPY for each of them. Or write a shell script that copies all files into one large file, then run the COPY once Commented Apr 7, 2021 at 6:51
  • can u please guide me in the shell script ? Commented Apr 7, 2021 at 6:56

1 Answer 1

1

you can load all files using:

 cat /md-data/vamshi/s3data/test_Hash*.csv | psql -c 'COPY testemail from stdin CSV HEADER'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.