I have a VARCHAR column with the value '2018-07-05T16:14:27.1427'
and I convert it to timestamp with this command:
select last_run,
to_char(to_timestamp(last_run,'yyyy-MM-dd HH24:mi:ss') - interval '2 hour','yyyy-MM-dd"T"HH24:mi:ss"Z"') as new_last_run
from schedule_tasks;
Until the version 9.6.10 of PostgreSQL, all works good, but now I will migrate to 10.5 and the same command returns ERROR. The same issue happens on PostgreSQL 11.
What I realize is that, on 9.6, the first value of milliseconds when I have 4 digits is added to seconds; for example, 2018-07-05T16:14:27.1427
converted is 2018-07-05T16:14:28.427
.
I don't know if this behavior is normal in the newer versions and I will have to handle it, or if this is a bug.
'2018-07-05T16:14:27.1427'::timestamp
Butto_timestamp()
should be told, that there are microseconds:to_timestamp(last_run, 'yyyy-mm-dd hh24:mi:ss.US')
varchar
column? If you had chose the correct data type you would not have that problem now.