Your current query has severals problems, two of which I think my answer can resolve. First, you are trying to insert an empty string ''
to handle NULL
values in the dojo
column. This won't work, because empty string is not a valid timestamp. As others have pointed out, one solution would be to use current_timestamp
as a placeholder.
Another problem you have is that you are incorrectly using to_char
to format your timestamp data. The output of to_char
is a string, and the way you are using it would cause Postgres to reject it. Instead, you should be using to_timestamp()
, which can parse a string and return a timestamp. Something like the following is what I believe you intend to do:
insert into employee (eid, dojo)
select 14, coalesce(to_timestamp(dojo, 'DD/MM/YYYY HH:MI:SS PM'), current_timestamp)
from employee;
This assumes that your timestamp data is formatted as follows:
DD/MM/YYYY HH:MI:SS PM (e.g. 19/2/1995 12:00:00 PM)
It also is not clear to me why you are inserting back into the employee
table which has non usable data, rather than inserting into a new table. If you choose to reuse employee
you might want to scrub away the bad data later.