UTF-8 Does not accept special characters PostgreSQL-SQL

0

Good morning I have created a database to store all the countries and cities and I am trying to load the data but even though my database is created with a utf-8 file like my tables. At the time of importing I also select UTF-8 but it gives me error of this type ERROR: invalid byte sequence for encoding "UTF8": 0xe3 0x6f 0x20 CONTEXT: COPY ciudades, line 23488 simply by receiving an accent, a ñ or any other special character. Any guidance that can help me would be grateful.

Next the SQL code:

-- Database: paises

-- DROP DATABASE paises;

CREATE DATABASE paises
    WITH 
    OWNER = postgres
    ENCODING = 'UTF8'
    LC_COLLATE = 'en_US.UTF-8'
    LC_CTYPE = 'en_US.UTF-8'
    TABLESPACE = pg_default
    CONNECTION LIMIT = -1;

-- La configuracion de la tabla

-- Table: public.ciudades

-- DROP TABLE public.ciudades;

CREATE TABLE public.ciudades
(
id_ciudad bigint NOT NULL,
id_pais_ciudad character varying(10) COLLATE pg_catalog."default" NOT NULL,
nom_ciudad character varying(100) COLLATE pg_catalog."default",
CONSTRAINT ciudades_pkey PRIMARY KEY (id_ciudad),
CONSTRAINT id_pais_ciudad FOREIGN KEY (id_pais_ciudad)
    REFERENCES public.paises (cod_pais) MATCH SIMPLE
    ON UPDATE NO ACTION
    ON DELETE NO ACTION
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;

ALTER TABLE public.ciudades
OWNER to postgres;
    
asked by Luis Alfredo Serrano Díaz 15.11.2018 в 14:28
source

1 answer

1

Your problem

You have a coding problem when supplying data to the DB (database). The database expects UTF-8 and you give something else that is not this.

Coding problem

Your problem is that you have somewhere in the data that you enter the wrong encoding.

If you use Windows, it usually happens that it has an ANSI , Windows-1252 encoding or, if you're in a non-Spanish-speaking country, even another encoding.

As you mentioned, you enter the data from a file using CSV. Well, in doing so, even though the program that exports data tells you that it is in UTF-8 code, it may not be.

You should make sure that both the query and the entered data are correctly coded in UTF-8 .

    
answered by 15.11.2018 / 15:05
source