【发布时间】:2017-05-06 00:13:46
【问题描述】:
使用 MySQL 5.7,我想知道 PostgreSQL 相当于
SELECT * FROM user_conversations WHERE JSON_CONTAINS(users, JSON_ARRAY(1))
JSON_CONTAINS(users, JSON_ARRAY(1)) 在 PostgreSQL 中怎么写
编辑 1
这是我的 json 它只是一个没有子对象的数组:
[
"john",
"doe",
"does"
]
我想以“doe”为例
编辑 2
我的桌子:
Column | Type | Modifiers | Storage | Statistics Target | Description
------------+--------------------------------+-------------------------------------------------------+----------+-----------------------+-------------
id | uuid | non NULL | plain | |
name | character varying(255) | non NULL | extended | |
image | character varying(255) | non NULL Par défaut, 'default.png'::character varying | extended | |
users | json | non NULL | extended | |
type | integer | non NULL | plain | |
emoji_id | integer | non NULL Par défaut, 0 | plain | |
created_at | timestamp(0) without time zone | | plain | |
updated_at | timestamp(0) without time zone |
编辑 3: 我使用 laravel 执行查询:
DB::table('user_conversations')->whereRaw('JSON_CONTAINS(users, JSON_ARRAY(1))')->orderBy('created_at', 'desc')->paginate(5);
它适用于 mysql。
【问题讨论】:
-
你看过library。顺便说一句,我从来没有使用过 mysql 版本,也没有使用过这个 pgsql 版本。只是认为这可能是一个不错的起点
-
This question 也可能是你的票
-
你能粘贴
user_conversations的架构吗? -
@EvanCarroll 查看我的最后编辑
标签: mysql postgresql laravel