Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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中的数组中排除?_Sql_Arrays_Postgresql - Fatal编程技术网

如何从postgresql中的数组中排除?

如何从postgresql中的数组中排除?,sql,arrays,postgresql,Sql,Arrays,Postgresql,我想在下面的查询中更改数组列call\u type的条件,以便它排除所有已“访问”的内容。 如何使用该阵列部件 select staff_id, COUNT(event_id) as offered from call_logs as logs where visit_offered and contact_date between now() - interval '1 weeks' and now() and provider_type = 'Contractor' and conta

我想在下面的查询中更改数组列
call\u type
的条件,以便它排除所有已“访问”的内容。
如何使用该阵列部件

select staff_id,
   COUNT(event_id) as offered
from call_logs as logs
where visit_offered
and contact_date between now() - interval '1 weeks' and now()
and provider_type = 'Contractor'
and contact_with != 'company_staff'
and direction = 'outbound'
and outcome = 'Successful'
and call_type && array  ['Schedule','schedule_visit']
group by staff_id;

要简单地将数组元素作为一个整体进行匹配请使用,否定:

AND  NOT call_type @> '{schedule_visit}'::text[]
注意数组包装器。通常不需要转换为
text[]
,但可以帮助避免歧义

如果列可以是
NULL
,并且您不想排除这些行:

AND  (call_type @> '{schedule_visit}'::text[]) IS NOT TRUE
可通过索引支持:

模式匹配更为复杂。使用不存在的
表达式:

AND NOT EXISTS (
   SELECT FROM unnest(logs.call_type) call
   WHERE  call ILIKE '%visit_occurred%'  -- case insensitive?
   )
对此没有索引支持。JSON数组的相关答案(原理相同):

另一种方法是将数组列规范化为一个单独的n:1表。

“排除所有已发生“访问”的内容”有点模糊。是要精确匹配数组元素还是标识包含给定字符串的元素?请随时公开你对Postgres的看法。