What would be the right way to identify null value when using JSON_EXTRACT,
I want to use a case statement to identify null values in a json field and if the value is null replace it with another value in this case 1.
CREATE TABLE `Log` (
`change` json DEFAULT NULL
) ENGINE=InnoDB AUTO_INCREMENT=345 DEFAULT CHARSET=utf32 COLLATE=utf32_unicode_ci;
insert into `Log` (`change`) values (JSON_OBJECT('documentNumber', 2));
insert into `Log` (`change`) values (JSON_OBJECT('documentNumber', null));
select case
when isnull(JSON_EXTRACT(`change`, '$.documentNumber')) = 1 then '1'
else JSON_EXTRACT(`change`, '$.documentNumber')
end as 'result'
from `Log`;
For this query i am getting result,
result
2
null
but i am expecting,
result
2
1