-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Closed
Description
- Laravel Version: 8.79.0
- PHP Version: 7.4.27
- Database Driver & Version: MariaDB 10.6.5, PostgreSQL 13.5
Description:
MariaDB supports a bitwise AND operator as follows:
SELECT 'a' WHERE (3 & 1);
PostgreSQL also does, but requires a bool cast like so:
SELECT 'a' WHERE (3 & 1):::bool;
The expression itself produces an integer, so I understand the necessity to cast in raw SQL.
However, given this operator is in the list of available ones, alongside other bitwise operators (e.g. |, ^, &~, etc...) I fail to see how it is supposed to be used.
Steps To Reproduce:
Let's pretend you have a Model named Order
, with a status
column. Since the status could be a combination of many, we'll use a bitmask in order to "combine" multiple status in one column.
Then, we should be able to query the table like this :
$query = Order::query();
// doing some stuffs
$query->where('status', '&', 1)->get();
This yields a PDOException
.
What we currently have to do :
$query = Order::query();
// doing some stuffs
$query->where($query->raw('(status & 1)'), '!=', 0)->get();
This could cause some problems, since the column name is no longer escaped.
Metadata
Metadata
Assignees
Labels
No labels