【发布时间】:2021-08-06 23:57:26
【问题描述】:
(使用 Postgres 9.5)
假设您有一个具有以下架构的 Postgres 表:
Table "public.tableA"
Column | Type | Collation | Nullable | Default
---------------+--------------------------+-----------+----------+----------------------------------------------
id | bigint | | not null | nextval('truelayer_tokens_id_seq'::regclass)
user_id | text | | not null |
created_at | timestamp with time zone | | | now()
updated_at | timestamp with time zone | | |
provider_id | text | | not null | ''::text
scopes | jsonb | | not null | '{}'::jsonb
在范围列内是各种 user_id 的以下数据的子集。
["A", "B", "C", "D", "E"]
- 有些用户会有范围:
["A"] - 有些用户会有范围:
["B","C","D"] - 有些用户会有范围:
["A","D"]
我想运行一个查询,返回特定 user_id 的所有行,其中“范围”中的数组包含值“A”
我什至很难开始使用这个,所以所有建议都值得赞赏。
【问题讨论】:
标签: postgresql jsonb postgresql-9.5