查找提供的列表 postgres 中不存在的值 [英] Find values not present in supplied list postgres

查看:90
本文介绍了查找提供的列表 postgres 中不存在的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试查找一个查询,该查询将告诉我数据库中没有的值.例如:

I am trying to find a query that will tell me the values that are not in my database. Eg:

      select seqID, segment from flu where seqID IN (1,2,3,4,5,6,7,8,9). 

现在,如果我的数据库没有 seqID 的 3,8,9,我将如何仅查找/显示丢失的 seqID.

Now if my database doesn't have seqID's 3,8,9 how would I find/display only the missing seqID's.

推荐答案

首先,由于您似乎是 Stackoverflow 的新手,这里有一些礼仪和发帖技巧:

First, since you appear to be new to Stackoverflow, here's a few etiquette and posting tips:

  • 始终包含相关的版本信息.在这里,你可能想要包含 PostgreSQL 的版本信息
  • 简要描述您想做什么
  • 包括任何相关的源代码(你做了;干得好)
  • 包括任何错误
  • 解释你想要的结果(你做了什么;干得好)
  • 跟进并标记答案.对很多人来说,如果你不给正确答案的功劳,他们不会帮助你.只是一个提示.

由于您没有执行上述所有操作,因此我只能猜测,因此我会根据您的代码做出一些假设.您似乎需要一个 EXCEPT 语句.以下代码是在 PostgreSQL 9.1 上开发的.

Since you didn't do all of the above, I'm left guessing, so I'm making some assumptions based on your code. You seem to need an EXCEPT statement. The following code was developed on PostgreSQL 9.1.

create temp table my_value(seq_id int);

insert into my_value(seq_id) values
(1), (2), (4), (5), (6), (7);

select unnest(array[1, 2, 3, 4, 5, 6, 7, 8, 9]) 
EXCEPT 
select distinct seq_id from my_value;

我假设您有一个硬编码的整数列表(如问题中的示例).我刚刚创建了一个用于测试和演示目的的临时表,但我相信您可以根据自己的情况进行必要的调整.如果您没有硬编码的整数列表,那么您只需要再次选择包含它的任何源.

I'm assuming that you are have a hard coded list of ints (like in your example in the question). I just created a temp table for testing and demo purposes, but I'm sure you can make the necessary adjustments to work in your situation. If you don't have a hard-coded list of ints, then you just need to do a select again whatever source would contain it.

希望这会有所帮助.欢迎使用 Stackoverflow.

Hope this helps. Welcome to Stackoverflow.

这篇关于查找提供的列表 postgres 中不存在的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆