Update 'Copy data to postgresql'

Guillem Borrell Nogueras 2023-01-17 17:43:02 +01:00
parent e45a729db6
commit 56e58b77b9

@ -31,11 +31,10 @@ head -n 100 /data/raw/BCG\ Report\ 01\ Customer\ Base\ Data\ -\ 2023-01-16.csv |
Then we want to create a new file striping the header Then we want to create a new file striping the header
``` ```
tail -n +2 /data/raw/data.csv | iconv -c -f ASCII -t UTF-8 > data.csv tail -n +2 /data/raw/data.csv | iconv -c -f ASCII -t UTF-8 | psql -U postgres -h localhost -c "\copy customer_base_data from stdin with (FORMAT 'csv', DELIMITER ',', QUOTE '\"')"
``` ```
And finally we can insert the file To change the semicolon separator with comma:
``` ```
psql -U postgres -h localhost -c "\copy customer_base_data from 'data.csv' with (FORMAT 'csv', DELIMITER ',', QUOTE '\"')" sed --expression='s/;/,/g'
``` ```