My table looks like this:
CREATE TABLE IF NOT EXISTS metering.service_point (
service_point_id int GENERATED ALWAYS AS IDENTITY NOT NULL PRIMARY KEY,
service_point_number varchar (20) NULL,
property_id int NULL,
fuel_type char (1) NULL,
ldz_id smallint NULL,
gsp_id smallint NULL,
supply_start_date timestamp NULL,
supply_end_date timestamp NULL);
I'm inserting data from a CSV that looks like this:
service_point_number, property_id, fuel_type, gsp_id, ldz_id, supply_start_date
'1717209598220',1,'E',8,,'20180428'
Using this command:
COPY metering.service_point (service_point_number, property_id, fuel_type, gsp_id, ldz_id, supply_start_date)
FROM 'C:BillingDataservice_point.csv'
DELIMITER ','
CSV HEADER;
This is the fourth table in a batch loading process, and the first three went fine. This one fails with: value too long for type character(1)
However, if I copy the contents DIRECTLY from the CSV and paste it into an INSERT
query, like this:
INSERT INTO metering.service_point (service_point_number, property_id, fuel_type, gsp_id, ldz_id, supply_start_date)
SELECT '1717209598220',1,'E',8,NULL,'20180428';
Then it works fine.
My assumption is that this must be a bug. I can work around it by setting the value to NULL, and then fixing it up later. I can also workaround the problem by changing the data type for fuel_type
, but this seems a little sad.
I guess I'm just missing something simple, maybe something unicode related - like the E
in my CSV actually counts as 2 characters for some strange reason?