Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 查找具有特定数组值的postgres jsonb列的所有行_Postgresql_Jsonb_Postgresql 9.5 - Fatal编程技术网

Postgresql 查找具有特定数组值的postgres jsonb列的所有行

Postgresql 查找具有特定数组值的postgres jsonb列的所有行,postgresql,jsonb,postgresql-9.5,Postgresql,Jsonb,Postgresql 9.5,(使用Postgres 9.5) 假设您有一个具有以下架构的Postgres表: Table "public.tableA" Column | Type | Collation | Nullable | Default ---------------+---------------

(使用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

在scopes列中是以下各种用户ID数据的子集。
[“A”、“B”、“C”、“D”、“E”]

  • 某些用户将具有作用域:
    [“A”]
  • 一些用户将具有作用域:
    [“B”、“C”、“D”]
  • 一些用户将具有作用域:
    [“A”,“D”]
我想运行一个查询,返回特定用户id的所有行,其中“scopes”中的数组包含值“a”


我甚至很难开始这样做,所以所有的建议都很受欢迎。

使用
jsonb
containment操作符
@

SELECT id, scopes
FROM "tableA"
WHERE scopes @> '["A"]';