From erouse@milner.com Thu Jul 6 19:13:09 2017 Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTCFH-0004Ol-5M for pgsql-sql@arkaria.postgresql.org; Thu, 06 Jul 2017 19:15:23 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dTCFG-0002Cy-1u for pgsql-sql@arkaria.postgresql.org; Thu, 06 Jul 2017 19:15:22 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dTCDD-0000C5-Ky for pgsql-sql@postgresql.org; Thu, 06 Jul 2017 19:13:15 +0000 Received: from hub029-va-8.exch029.serverdata.net ([199.193.200.199]) by makus.postgresql.org with esmtps (TLS1.0:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1dTCD9-0002nJ-P6 for pgsql-sql@postgresql.org; Thu, 06 Jul 2017 19:13:14 +0000 Received: from MBX029-E1-VA-10.exch029.domain.local ([10.216.105.60]) by HUB029-VA-8.exch029.domain.local ([10.216.105.236]) with mapi id 14.03.0319.002; Thu, 6 Jul 2017 12:13:09 -0700 From: Ed Rouse To: "pgsql-sql@postgresql.org" Subject: Finding the negative Thread-Topic: Finding the negative Thread-Index: AdL2i+erhr9cSSp4Q02wX4frrlE4rQ== Date: Thu, 6 Jul 2017 19:13:09 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [209.155.237.189] Content-Type: multipart/alternative; boundary="_000_DE8D456CF535514BB21272D05C4A1C391E66AB2Embx029e1va10exc_" MIME-Version: 1.0 List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org --_000_DE8D456CF535514BB21272D05C4A1C391E66AB2Embx029e1va10exc_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Version 9.1. I have the following query that brings back the correct number of lobs stil= l asscociated with data in other tables: select count(distinct(loid)) from pg_largeobject where (loid in (select con= tent from attachments) or loid in (select content from idw_form_workflow_at= tachments)); in that the loid's in either table are found. What I need is to find the on= es NOT in either table. I have tried using not in both with or/and and var= ious parenthesis. I tried: select count(distinct(loid)) from pg_largeobject where not ((loid in (selec= t content from attachments) or loid in (select content from idw_form_workfl= ow_attachments))); This should work since, if the loid is not in the content of either table, = it should be F or F =3D F, negated to T; which I would think would then count, but I get back 0 instead of the rathe= r large number I should get. This is all a prelude to removing lobs that ar= e no longer referenced. Any ideas on how to get the inverse of the working query? Thanks --_000_DE8D456CF535514BB21272D05C4A1C391E66AB2Embx029e1va10exc_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Version 9.1.

I have the following query that brings back the corr= ect number of lobs still asscociated with data in other tables:<= /p>

 

select count(distinct(loid)) from pg_largeobject whe= re (loid in (select content from attachments) or loid in (select content fr= om idw_form_workflow_attachments));

 

in that the loid’s in either table are found. = What I need is to find the ones NOT in either table. I have tried using not= in both with or/and  and various parenthesis. I tried:

 

select count(distinct(loid)) from pg_largeobject whe= re not ((loid in (select content from attachments) or loid in (select conte= nt from idw_form_workflow_attachments)));

 

This should work since, if the loid is not in the co= ntent of either table, it should be F or F =3D F, negated to T;<= /p>

which I would think would then count, but I get back= 0 instead of the rather large number I should get. This is all a prelude t= o removing lobs that are no longer referenced.

 

Any ideas on how to get the inverse of the working q= uery? Thanks

--_000_DE8D456CF535514BB21272D05C4A1C391E66AB2Embx029e1va10exc_-- From vinny@xs4all.nl Thu Jul 6 19:25:20 2017 Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTCQ8-0004xI-Gy for pgsql-sql@arkaria.postgresql.org; Thu, 06 Jul 2017 19:26:36 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dTCQ7-0004OU-M4 for pgsql-sql@arkaria.postgresql.org; Thu, 06 Jul 2017 19:26:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dTCP5-0002cs-Vg for pgsql-sql@postgresql.org; Thu, 06 Jul 2017 19:25:32 +0000 Received: from lb3-smtp-cloud3.xs4all.net ([194.109.24.30]) by magus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1dTCOy-0005X9-Ry for pgsql-sql@postgresql.org; Thu, 06 Jul 2017 19:25:31 +0000 Received: from [10.0.0.130] ([92.108.133.107]) by smtp-cloud3.xs4all.net with ESMTP id hXRL1v00F2KBR2L01XRN2b; Thu, 06 Jul 2017 21:25:23 +0200 Subject: Re: Finding the negative To: Ed Rouse , "pgsql-sql@postgresql.org" References: From: Vincent Elschot Message-ID: Date: Thu, 6 Jul 2017 21:25:20 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------DC5346A448E95F924D34ED91" Content-Language: nl List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org This is a multi-part message in MIME format. --------------DC5346A448E95F924D34ED91 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Op 06/07/2017 om 21:13 schreef Ed Rouse: > > Version 9.1. > > I have the following query that brings back the correct number of lobs > still asscociated with data in other tables: > > select count(distinct(loid)) from pg_largeobject where (loid in > (select content from attachments) or loid in (select content from > idw_form_workflow_attachments)); > > in that the loid’s in either table are found. What I need is to find > the ones NOT in either table. I have tried using not in both with > or/and and various parenthesis. I tried: > > select count(distinct(loid)) from pg_largeobject where not ((loid in > (select content from attachments) or loid in (select content from > idw_form_workflow_attachments))); > > This should work since, if the loid is not in the content of either > table, it should be F or F = F, negated to T; > > which I would think would then count, but I get back 0 instead of the > rather large number I should get. This is all a prelude to removing > lobs that are no longer referenced. > > Any ideas on how to get the inverse of the working query? Thanks > Isn't this a case for EXCEPT, the reverse of UNION? Like in: SELECT COUNT(*) FROM ( SELECT foo FROM bar EXCEPT SELECT foo FROM cafe ) --------------DC5346A448E95F924D34ED91 Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: 8bit



Op 06/07/2017 om 21:13 schreef Ed Rouse:

Version 9.1.

I have the following query that brings back the correct number of lobs still asscociated with data in other tables:

 

select count(distinct(loid)) from pg_largeobject where (loid in (select content from attachments) or loid in (select content from idw_form_workflow_attachments));

 

in that the loid’s in either table are found. What I need is to find the ones NOT in either table. I have tried using not in both with or/and  and various parenthesis. I tried:

 

select count(distinct(loid)) from pg_largeobject where not ((loid in (select content from attachments) or loid in (select content from idw_form_workflow_attachments)));

 

This should work since, if the loid is not in the content of either table, it should be F or F = F, negated to T;

which I would think would then count, but I get back 0 instead of the rather large number I should get. This is all a prelude to removing lobs that are no longer referenced.

 

Any ideas on how to get the inverse of the working query? Thanks


Isn't this a case for EXCEPT, the reverse of UNION? Like in:
SELECT COUNT(*) FROM
(
SELECT foo  FROM bar
EXCEPT
SELECT foo FROM cafe
)
--------------DC5346A448E95F924D34ED91-- From tgl@sss.pgh.pa.us Thu Jul 6 19:43:23 2017 Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTChY-0005qE-Jh for pgsql-sql@arkaria.postgresql.org; Thu, 06 Jul 2017 19:44:36 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dTChX-0006uL-H2 for pgsql-sql@arkaria.postgresql.org; Thu, 06 Jul 2017 19:44:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dTCgY-00057c-BG for pgsql-sql@postgresql.org; Thu, 06 Jul 2017 19:43:34 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dTCgQ-0005sa-Ru for pgsql-sql@postgresql.org; Thu, 06 Jul 2017 19:43:33 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v66JhNEi026803; Thu, 6 Jul 2017 15:43:23 -0400 From: Tom Lane To: Ed Rouse cc: "pgsql-sql@postgresql.org" Subject: Re: Finding the negative In-reply-to: References: Comments: In-reply-to Ed Rouse message dated "Thu, 06 Jul 2017 19:13:09 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <26801.1499370203.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 06 Jul 2017 15:43:23 -0400 Message-ID: <26802.1499370203@sss.pgh.pa.us> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org Ed Rouse writes: > ... What I need is to find the ones NOT in either table. I have tried usi= ng not in both with or/and and various parenthesis. I tried: > select count(distinct(loid)) from pg_largeobject where not ((loid in (sel= ect content from attachments) or loid in (select content from idw_form_work= flow_attachments))); > This should work since, if the loid is not in the content of either table= , it should be F or F =3D F, negated to T; > which I would think would then count, but I get back 0 instead of the rat= her large number I should get. I'm suspicious that this means there's at least one NULL in those content columns. That will cause the IN check to return either TRUE or NULL, not FALSE. You could recast to use EXISTS, or explicitly exclude nulls while selecting from the attachments tables. regards, tom lane --=20 Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql