From 56e58b77b94306a0019d235c49eb2812d3e73095 Mon Sep 17 00:00:00 2001 From: Guillem Borrell Nogueras Date: Tue, 17 Jan 2023 17:43:02 +0100 Subject: [PATCH] Update 'Copy data to postgresql' --- Copy-data-to-postgresql.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Copy-data-to-postgresql.md b/Copy-data-to-postgresql.md index d238dea..dd27512 100644 --- a/Copy-data-to-postgresql.md +++ b/Copy-data-to-postgresql.md @@ -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 ``` -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' ``` \ No newline at end of file