Pastor Colome
Pastor Colome

Reputation: 9

Postgres COPY importing wrong character for ñ

Wrong characters are shown in Postgres Database when I do a COPY of a csv file with the encoding WIN1252.

It works fine in postgres database 11.3 with datcollate and datctype encodings en_US.UTF8 and es_ES.UTF8, in both databases ñ character is show correctly after COPY.

It doesn´t work in postgres database 9.4.9 with datcollate and datctype encodings en_US.UTF8

This is the COPY sql instruction that I´m using:

COPY tmp_divisionzonaUE(Id,version,COMPAÑIA,COD_UE,UNIDAD_EJECUCION,DIVISION,COD_UG,U_GESTION,COD_UC,U_COORDINACION,UE_PROVINCIA,UE_DIRECCION,UE_CP,UE_AREA_DESPLIEGE,UE_COD_SIEMENS,UE_COD_TERRITORIO,UE_COD_DIVISION,UE_COD_PROVINCIA,UE_COD_LOCALIDAD)"+ " FROM STDIN WITH (FORMAT TEXT, ENCODING 'WIN1252', DELIMITER ';'," + " HEADER false)

UPDATE: I have check that the problem is where I launch COPY code, if I launch it windows machine and csv file is storage in windows machine ñ characters are shown correctly in the database but if I launch COPY code in linux machine and csv file is storage in linux machine ñ characters are not shown correctly.

UPDATE2: In linux machine if I launch COPY from eclipse (because it is inside Java code) the ñ character appear well in database but If I launch the same jar file in the command line with java -jar filename the ñ characters doesn´t appear well.

Upvotes: 0

Views: 922

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 246808

You should specify the encoding of the file in the ENCODING option of the COPY command.

ENCODING

Specifies that the file is encoded in the encoding_name. If this option is omitted, the current client encoding is used. See the Notes below for more details.

Upvotes: 1

Related Questions