This is an example of success:
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 -select insert is a null expression.
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 explicit null in the second column, I have new_data , which is returned as null from the delete statement.
If both values ββare zero, why does the second example knock me down with this error? I walked over them carefully, and this is the only functional difference.
casting sql postgresql common-table-expression
John O Jul 03 '15 at 16:47 2015-07-03 16:47
source share