I have a table like this :
"id": 1562,
"creation_date": "2023-06-23 14:35:42.249",
activation": {
"updateDate": 1.687523742249E9,
"euid": "test",
"statusUpdateDate": 1.687523742249E9,
"standalone": false,
"variationCode": null,
"idohp": "test",
"creationDate": 1.687523742244E9,
"partnerVariationValue": null,
"variableCharacteristics": null,
"basicProduct": "test",
"variationValue": null,
"partner": "test",
"updateSource": "test",
"partnerTransactionId": null,
"noEuidReuse": false,
"id": 496,
"status": "CREATED"
},
"history_version": 1,
"update_date": "2023-06-23 14:35:42.249"
I want to update updateDate, statusUpdateDate from the timestamp format to 2023-06-23 14:35:42.249 format
I have tried some combination of to_date and to_timestamp but i am always getting an error due to the timestamp format and could not find a way to solve this
EDIT
to update one json field here is the request
update t_activation_history set activation = activation || (jsonb_build_object('updateDate', to_jsonb(to_timestamp((activation->>'updateDate')::numeric)))) where id = 1566;
Both
object.activation.statusUpdateDateandobject.activation.updateDateare epoch timestamps - seconds after 1970-01-01 00:00Z.to_timestampconverts these totimestamptz. So extract the values asnumericand useto_timestampfunction. Here is an illustration with your sample data astCTE. Please note the use ofjsonb_settwo times.To make a long story short - extract the epoch timestamp value as text, cast it as numeric and call
to_timestampwith the resulting number.Edit
A bit shorter using
||operator