SQLSTATE[HY000]: General error: 1 too many SQL variables (SQL: select * from "sale_points" where "sale_points"."uuid" in (98cc2251-4665-46f2-afbf-ed432a69555b, ..., 98cc225f-3f4c-4 998135d4-14de-4376-b91b-ecefff1ebf1c, 99c16b76-1721-4668-8d50-460ae6c115af)) at /home/salcom/public_html/sam-central/vendor/laravel/framework/src/Illuminate/Database/Connection.php:760)
This error popped up in production today but there haven't been any changes in the code so I don't know what is happening.
This is the method there it fails, this is an api backend
public function salePoints($action, $updatedAt = null)
{
if ($action === SyncAction::MASTER->value)
//fails on the line below
return GpsSalePointResource::collection(SalePoint::withTrashed()->with('salePoint')->oldest()->lazy())->resolve();
else
return GpsSalePointResource::collection(SalePoint::withTrashed()->with('salePoint')->whereTimestamps('>', Carbon::parse($updatedAt))->oldest()->lazy())->resolve();
}
GpsSalePointResource
class GpsSalePointResource extends JsonResource
{
public function toArray($request)
{
return [
'id' => $this->id,
'uuid' => $this->salePoint->uuid,
'code' => $this->code,
'name' => $this->salePoint->name,
'client_name' => $this->client_name,
'business_name' => $this->salePoint->business_name,
'longitude' => $this->salePoint->longitude,
'latitude' => $this->salePoint->latitude,
'format_id' => $this->format_id,
'district_id' => $this->salePoint->district_id,
'distributor_id' => $this->distributor_id,
'sale_point_type_id' => $this->sale_point_type_id,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'deleted_at' => $this->deleted_at
];
}
}
What could cause this error all of a sudden?
Edit, it seems to be the amount of ids in the where in clause, right now it shows 2000 exactly, how can I chunk or split it up so it doesn't throw this error?
What is the right way to do something like this query without getting this error?