Ho creato un database UTF8, aggiunto una tabella e inserito i due caratteri UTF-8 su cui il COPY si bloccava — e con INSERT ha funzionato senza problemi:
CREATE DATABASE test WITH OWNER = postgres ENCODING = 'UTF8' TABLESPACE = pg_default LC_COLLATE = 'English_United States.1252' LC_CTYPE = 'English_United States.1252' CONNECTION LIMIT = -1; CREATE TABLE x (first_two_letters character(3)) WITH (OIDS=FALSE); ALTER TABLE x OWNER TO postgres; INSERT INTO x(first_two_letters) VALUES ('سر');Secondo https://rishida.net/tools/conversion/, i code point Unicode del COPY che fallisce sono:
che sono due caratteri — quindi dovrebbero entrare in una colonna dichiarata character(3), che contiene fino a 3 caratteri (non byte). E infatti l'INSERT riesce:
INSERT INTO x(first_two_letters) VALUES (U&'\0633\0631');Secondo la documentazione di pg_dump, puoi usare INSERT al posto di COPY con l'opzione --inserts. Prova questo per il passo 1:
pg_dump -U postgres -t OldSchema."TableToCopy" --inserts OldDatabase > Table.sqlHo anche provato a copiare una tabella su file e a reimportarla con COPY, e anche in quel caso ha funzionato. Sei sicuro che sia la codifica del client sia quella del server siano UTF8?
Per cominciare, esporta la tabella x dallo schema public del database test verso un file SQL in testo semplice:
pg_dump -U postgres -t public."x" test > x.sqlViene così prodotto un file x.sql contenente:
-- -- PostgreSQL database dump -- SET statement_timeout = 0; SET lock_timeout = 0; SET client_encoding = 'UTF8'; SET standard_conforming_strings = on; SET check_function_bodies = false; SET client_min_messages = warning; SET search_path = public, pg_catalog; SET default_tablespace = ''; SET default_with_oids = false; -- -- Name: x; Type: TABLE; Schema: public; Owner: postgres; Tablespace: -- CREATE TABLE x (first_two_letters character(3)); ALTER TABLE public.x OWNER TO postgres; -- -- Data for Name: x; Type: TABLE DATA; Schema: public; Owner: postgres -- COPY x (first_two_letters) FROM stdin; سر \. -- -- PostgreSQL database dump complete --Poi importalo con:psql -U postgres -d test -f x.sql