0

我有一个表,其中包含一个名为“数据”的列,其中包括:

{"id":1074,"opened":true,"subscribed":true}

我想要一个按这些属性过滤的查询。

我试过了

->whereRaw('JSON_EXTRACT(data, "$.opened")', false)

->where('data->opened', false)

回复:

PDOException: 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 '>'$."id"' = ? and `data`->'$."opened"' = false order by `created_at` desc' at line 1 in.....

我知道此代码适用于 MySQL 5.7,但我的服务器正在运行“10.1.34-MariaDB-0”,我无法更改为 MySQL,因为 Plesk 不支持它。

4

1 回答 1

1

MariaDB 目前不支持 Json 类型。

如果您遇到困难并且需要它来使用 MariaDB。尝试使用元表。

+----+------------+------------+-------+
| id | foreign_id | name       | value |
+----+------------+------------+-------+
| 1  | 1074       | subscribed | 1     |
+----+------------+------------+-------+
| 2  | 1074       | opened     | 0     |
+----+------------+------------+-------+
于 2018-10-05T08:43:27.633 回答