sql 查询将使用@> 运算符,例如:
t=# with cnms_rosters(agents) as (values('[1,13,3,16,15]'::jsonb),('[12,13,14,15,15]'),('[11,73,55,16,44]'))
select agents FROM cnms_rosters where agents @> '[13]'::jsonb;
agents
----------------------
[1, 13, 3, 16, 15]
[12, 13, 14, 15, 15]
(2 rows)
或
t=# with cnms_rosters(agents) as (values('[1,13,3,16,15]'::jsonb),('[12,13,14,15,15]'),('[11,73,55,16,44]'))
select agents FROM cnms_rosters where agents @> '[16]'::jsonb;
agents
----------------------
[1, 13, 3, 16, 15]
[11, 73, 55, 16, 44]
(2 rows)
和数组一样:
t=# with cnms_rosters(agents) as (values(array[1,13,3,16,15]),(array[12,13,14,15,15]),(array[11,73,55,16,44]))
select agents FROM cnms_rosters where agents @> array[13];
agents
------------------
{1,13,3,16,15}
{12,13,14,15,15}
(2 rows)
或
t=# with cnms_rosters(agents) as (values(array[1,13,3,16,15]),(array[12,13,14,15,15]),(array[11,73,55,16,44]))
select agents FROM cnms_rosters where agents @> array[16];
agents
------------------
{1,13,3,16,15}
{11,73,55,16,44}
(2 rows)