Reputation: 39
I am using Laravel 5.5 and I am unable to delete the notification using the below query. It gives the following error :
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '>video_id=89' at line 1 (SQL: delete from
notifications
where data->video_id=89).
DB::table('notifications')->WhereRaw("data->video_id=$video_id")->delete();
Upvotes: 0
Views: 1778
Reputation: 62348
The ->
operator is shorthand for the JSON_EXTRACT()
function in MySQL. Unfortunately, MariaDB does not support this shorthand syntax.
MariaDB did introduce the JSON_* functions in 10.2.3, but I do not know if they will work on columns in a query. Best thing you can do is try. You will need to rewrite your query to explicitly use the JSON_EXTRACT()
function:
DB::table('notifications')
->whereRaw('JSON_EXTRACT(data, "$.video_id") = ?', [$video_id])
->delete();
If this doesn't work, then you'll either need to switch from MariaDB to MySQL, or you'll need to rewrite your query as a simple string search (using the LIKE
operator).
Upvotes: 0
Reputation: 201
Why are you using data->video_id
Just try with
WhereRaw("video_id=$video_id")
Upvotes: 0