0

I'm triying to load data to PosgreSQL Data Base remotly by command Line in CMD, copying data from CSV file to a specific Table. It was working well but, somehow when I try to load data now, CMD throws me this error

enter image description here

Curiously CSV file has the "fecha_carga" field in date type as well is in the table storage in Data Base in this way, here is my try:

psql -h suggestedorder.postgres.database.azure.com -d DataAnalytics -U dev_ext@suggestedorder -c "TRUNCATE planning.env_cat_bloqueados" -c "\copy planning.env_cat_bloqueados (key, bloqueado, fecha_carga)from 'C:\Users\geradiaz.MODELO\Desktop\Envase\Catalogos\Outputs_Catalogos\Catalogo_Bloqueados\Catalogo_Bloqueados_Output.csv'with delimiter as ','

Can someone explain me what is happening here? and how could I fixed it up?

Best regards and thanks!

Xkid
  • 338
  • 1
  • 4
  • 17

2 Answers2

1

First please do not use images for textual data, instead copy and paste text. Second I'm guessing the CSV file has a header that has the column heading fecha_carga for the field. Since you did not specify HEADER along with DELIMITER in the WITH the COPY is taking the header line as data and fecha_carga is not a valid date.

Adrian Klaver
  • 15,886
  • 2
  • 17
  • 28
1

The @Adrian Klaver comment gave me the idea what was wrong with my command line, in effect the fields on my CSV file was taking as data, so I changed the command line specifying that my CSV file has headers by using the next instruction at the end instead with delimiter as ',' :

with (format csv, header) 

So, this is the whole command line:

psql -h suggestedorder.postgres.database.azure.com -d DataAnalytics -U dev_ext@suggestedorder -c "TRUNCATE planning.env_cat_bloqueados" -c "\copy planning.env_cat_bloqueados (key, bloqueado, fecha_carga)from 'C:\Users\geradiaz.MODELO\Desktop\Envase\Catalogos\Outputs_Catalogos\Catalogo_Bloqueados\Catalogo_Bloqueados_Output.csv'with (format csv, header)

Thanks!

Xkid
  • 338
  • 1
  • 4
  • 17