I am trying to import data into PostgreSQL with NULL
values in Windows 7.
"Code1.2";"08";"ALCALA";"ACTIVO SERVICIO";"EN SERVICIO";"";"2017/04/08";1
"Code1.3";"46";"BARCELONA";"ACTIVO SERVICIO";"EN SERVICIO";"";"2009/07/01";0
I don't want to import quotes "data"
neither ""
values.
CREATE TABLE IF NOT EXISTS public.TABLA1 (
CODIGO text,
COD text,
MUNICIPIO text,
ESTADO text,
SITUACION text,
FECHA_INICIO date,
FECHA_FIN date,
CONTADOR numeric
);
If I import data with the following I can handle NULL
values, but I have the ""
in the data:
COPY public.TABLA1 (
CODIGO,
COD,
MUNICIPIO,
ESTADO,
SITUACION,
FECHA_INICIO,
FECHA_FIN,
CONTADOR
)
FROM 'C:\DATA\ORIGEN\fichero_prueba.csv'
WITH (DELIMITER ';', NULL '""');
| CODIGO | COD | MUNICIPIO | ESTADO |SITUACION |FECHA_INICIO|...
| --------- | ---- | --------- | ----------------|-------------|------------|...
| "Code1.2" | "08" |"ALCALA" |"ACTIVO SERVICIO"|"EN SERVICIO"|[null] |...
| "Code1.3" | "46" |"BARCELONA"|"ACTIVO SERVICIO"|"EN SERVICIO"|[null] |...
...
On the other hand If I import the data with the following, trying to leave the quotation marks out:
COPY public.TABLA1 (
CODIGO,
COD,
MUNICIPIO,
ESTADO,
SITUACION,
FECHA_INICIO,
FECHA_FIN,
CONTADOR
)
FROM 'C:\DATA\ORIGEN\fichero_prueba.csv'
WITH DELIMITER ';' CSV QUOTE '"' NULL '""';
ERROR: CSV quote character must not appear in the NULL specification
And not using NULL
:
COPY public.TABLA1 (
CODIGO,
COD,
MUNICIPIO,
ESTADO,
SITUACION,
FECHA_INICIO,
FECHA_FIN,
CONTADOR
)
FROM 'C:\DATA\ORIGEN\fichero_prueba.csv'
WITH DELIMITER ';' CSV QUOTE '"';
ERROR: invalid input syntax for type date: «»
How can I import the data without the ""
and handle NULL
values in date types?
NULL
and the quotation marks are showing because those values are, in fact, strings. If that's not what you want then try to thoroughly explain the expected behavior.QUOTE '"'
to theCOPY
statement, maybe try that.