Answer the question
In order to leave comments, you need to log in
Why can't I use where, but only whereRaw?
I am writing a query to a POSTGRESQL database with two JOINs, I am seeing strange magic. whereIn
If I use or anywhere in the query where
, then POSGRESQL swears something like this:
ERROR: bind message supplies 3 parameters, but prepared statement \"pdo_stmt_00000009\" requires 4
whereRaw
, then the error goes away and everything works as expected. Of course, you can live with using whereRaw
, but still I would like to understand the reason for this behavior $table = DB::
table("stocks")->
select("products.product_id")->
selectRaw("SUM(stocks.quantity_full) AS quantity_full")->
selectRaw("SUM(stocks.in_way_to_client) AS in_way_to_client")->
selectRaw("SUM(stocks.in_way_from_client) AS in_way_from_client")->
rightJoin("sizes", "sizes.barcode", "=", "stocks.size_id")->
rightJoin("products", function($join) use($brands, $subject) {
return $join->
on("sizes.product_id", "=", "products.product_id")->
whereRaw("products.brand IN (".implode($b.")")->
when($subject > 0, function($query) use($subject) {
return $query->whereRaw("products.subject_id = ". $subject);
});
})->
groupBy("products.product_id");
Answer the question
In order to leave comments, you need to log in
The answer turned out to be quite simple - you need to read the documentation
more carefully. The
problem was the use of the specified request inside another request via leftJoin
. Instead, it was necessary to useleftJoinSub
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question