I started to follow the official documentation of gcp in order to import my csv data to an instance on cloud spanner spanner, but I’m getting thhis error:
*Error java.time.format.DateTimeParseException: Text '2024-05-30THH24:16:30.892' could not be parsed at index 10*
I’m using this command to generate the csv file:
psql -h localhost -U myuser -d mydatabase -c
"Copy (SELECT id, TO_CHAR(created_at, 'YYYY-MM-DD"T"HH24:MI:SS.MS') AS created_at FROM mytable) To STDOUT With CSV DELIMITER ',';" > /mycarpet/.csv
The table has this configuration:
id character varying(10) NOT NULL,
created_by character varying(50),
On the configuration of the job I’m setting: dateFormat=yyyy-MM-dd hh:mm:s
Any idea, how I can solve this?
2
Answers
The problem seems to be that your export from PostgreSQL results in invalid data being generated. The import job complains that
'2024-05-30THH24:16:30.892'
is not a valid date/time string, which is obviously a correct conclusion. Your export seems to be writing the fixed stringHH24
to the file, instead of the actual hour.I would recommend that you manually inspect:
SELECT id, TO_CHAR(created_at, 'YYYY-MM-DD"T"HH24:MI:SS.MS') AS created_at FROM mytable
in psql.Tip: As you seem to try to copy data from a PostgreSQL database to a Spanner PostgreSQL database, you can also use PGAdapter to copy it directly without going through a csv file. See this example for how to do that.
To expand on my comment:
Timestamps are not stored formatted, that is something done on presentation to the user. You can change that presentation using DateStyle or by using the Data formatting function
to_char()
. If the data is going to be ingested by another program any common date format should work in getting the correct information copied over.