This is an example of it succeeding:
with x as (
delete from common.companies where id = '0f8ed160-370a-47bb-b4bf-2dcf79100a52'
returning row_to_json(companies) as old_data, null as new_data, 'common.companies' as model, id, 'delete' as action)
insert into edit_history (old_data, new_data, model, model_pk, action, submitter)
select old_data, null, model, id, action, '0b392013-f680-45a6-b19a-34f3d42d0120' from x;
INSERT 0 1
Note that the second column in the insert-select is explicity null.
Here is an example that fails:
with x as (
delete from common.companies where id = '160d7ef2-807c-4fe0-bfed-7d282c031610'
returning row_to_json(companies) as old_data, null as new_data, 'common.companies' as model, id, 'delete' as action)
insert into edit_history (old_data, new_data, model, model_pk, action, submitter)
select old_data, new_data, model, id, action, '0b392013-f680-45a6-b19a-34f3d42d0120' from x;
ERROR: failed to find conversion function from unknown to json
Note in this example that instead of an explicit null in the second column, I've got new_data
, which is returned as null from the delete statement.
If both values are null, why does the second example clobber me with this error? I've been over both carefully, and this is the only functional difference.
See Question&Answers more detail:
os