使用WHERE子句选择postgresql数组不包含特定值的行?

时间:2018-04-13 10:25:34

标签: sql postgresql

在以下示例中, credentials = new ProfileCredentialsProvider("default").getCredentials(); AWSCostAndUsageReportClientBuilder reportBuilder = AWSCostAndUsageReportClientBuilder.standard(); AWSCostAndUsageReportClient costAndUsageReport = (AWSCostAndUsageReportClient) reportBuilder .withCredentials(new AWSStaticCredentialsProvider(credentials)) .withRegion("us-east-1") .build(); ReportDefinition reptDefinition = new ReportDefinition(); reptDefinition.setReportName("ChandraReport123"); reptDefinition.setTimeUnit("DAILY"); reptDefinition.setCompression("ZIP"); ArrayList addidtionSchemaElements = new ArrayList(); addidtionSchemaElements.add("RESOURCES"); reptDefinition.setAdditionalSchemaElements(addidtionSchemaElements); reptDefinition.setS3Bucket("etho-onnu22"); reptDefinition.setS3Prefix("someprefix"); reptDefinition.setS3Region("us-east-1"); reptDefinition.setFormat("textORcsv"); request.setReportDefinition(reptDefinition); PutReportDefinitionResult reportResult = costAndUsageReport.putReportDefinition(request); 列是parents arrayint)。

如果我想选择parents INT[]数组包含parents的所有行,我可以运行此查询:

42

现在我想反过来选择SELECT * FROM records WHERE 42 = ANY (parents); 包含parents的每一行。

我试过了:

42
没有运气......有谁知道如何做到这一点?

我正在使用Postgresql SELECT * FROM records WHERE 42 != ANY (parents);

2 个答案:

答案 0 :(得分:1)

SELECT * FROM records WHERE NOT (42 = ANY (parents))

<强>演示

  

http://sqlfiddle.com/#!17/394c0/1

答案 1 :(得分:0)

检查示例。 参考 - &gt; Refrence link

SELECT value_variable = ANY ('{1,2,3}'::int[])