I am working on laravel project using mysql. Recently I updated my ubuntu and after that I am getting error while fetching data from mysql db using json_extract()
method in where clause.
Until today I was able to fetch data using below code in laravel model:
return self::where([
'transaction_details->compensation_status' => Compensation::GIVEN,
'transaction_type' => self::COMPENSATION,
'transaction_details->compensation_type' => Compensation::MANUAL
])->orderBy('updated_at')->get();
Here transaction_details
column holds the json data, while transaction_type
is an integer column.
So above code when dumped, it gives me the SQL query:
select * from `transactions` where (json_unquote(json_extract(`transaction_details`, '$."compensation_status"')) = 1 and `transaction_type` = 7 and json_unquote(json_extract(`transaction_details`, '$."compensation_type"')) = 2) order by `updated_at` asc
And when I run this query I am getting some unexpected error:
#3141 - Invalid JSON text in argument 1 to function json_extract: "Missing a comma or '}' after an object member." at position 196.
I also tried make this query shorter, keeping only one condition so that I can get rid of any error at position 196.
select * from `transactions` where json_unquote(json_extract(`transaction_details`, '$."compensation_status"')) = 1 order by `updated_at` asc
Now this query do not have anything at position 196 but still the same error.
I guess this the bug in latest mysql.
Please do help me in this regards.
EDIT:
This is the json data the transaction_details
holds
{"message":"fgdfgdfg","referral_compensation_date":"2019-11-30","compensation_status":1,"compensation_type":2,"allocated_count":"-NA-","daily_job_count":"-NA-","allocation_date":"2019-11-30"}