Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZchW1-0000SP-9g for pgsql-admin@arkaria.postgresql.org; Thu, 17 Sep 2015 22:18:53 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZchW0-0006OG-Fa for pgsql-admin@arkaria.postgresql.org; Thu, 17 Sep 2015 22:18:52 +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) (envelope-from ) id 1ZchW0-0006Nz-0o for pgsql-admin@postgresql.org; Thu, 17 Sep 2015 22:18:52 +0000 Received: from mail-wi0-x235.google.com ([2a00:1450:400c:c05::235]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZchVx-0001r8-0i for pgsql-admin@postgresql.org; Thu, 17 Sep 2015 22:18:51 +0000 Received: by wicge5 with SMTP id ge5so9355912wic.0 for ; Thu, 17 Sep 2015 15:18:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-type:content-transfer-encoding; bh=/uV2W9D6IC4Gdh4co4IWShyh0J01ZlXTBAYKPYA5yaw=; b=iWCWXTvFj4vdGJWeW3p2Zj7uagBO5MhC06/G0HD062cN+Bf9DgGL+SQVOcKSk10hU9 VfeqRk+PVizZ7JdAtTVPIEJF3kZcGZvqn1wP2EHVIWbAZ6Fh3ENPfui+//sORDW79NKn xVXC/tzvC4NXsNO369yXvjoCNX/Et8zrBbMW2mgwlsX8clSj8a62YVNnsPpWgLVNkhbr T4pwIztLuHO03aF3KeGSluk3AfcQXOUutAu64lACeviWayl9375Jr/I6P/oae0C8ogzM k9qwpEAaNuTUi31ZfgeJP+ocY2Vun3fWJJy3g1J8cMCaSDowWRvOGRVq7+utVE8Y+qfY stTQ== X-Received: by 10.194.58.177 with SMTP id s17mr3108065wjq.102.1442528328258; Thu, 17 Sep 2015 15:18:48 -0700 (PDT) Received: from ?IPv6:2605:6000:f686:8500:2c3a:5d1b:9770:4776? ([2605:6000:f686:8500:2c3a:5d1b:9770:4776]) by smtp.gmail.com with ESMTPSA id xw2sm5568998wjc.12.2015.09.17.15.18.46 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Sep 2015 15:18:47 -0700 (PDT) Subject: Re: string not equal query, postgresql 9.4.4 To: Albe Laurenz , "pgsql-admin@postgresql.org" References: <55FA13F1.7060204@gmail.com> From: John Scalia X-Enigmail-Draft-Status: N1110 Message-ID: <55FB3C42.6030301@gmail.com> Date: Thu, 17 Sep 2015 17:18:42 -0500 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-admin Precedence: bulk Sender: pgsql-admin-owner@postgresql.org On 9/17/2015 7:54 AM, Albe Laurenz wrote: > John Scalia wrote: >>>> Having a bit of a head-scratching problem. I'm writing a query where I= want to output only distinct >>>> rows where one char(4) field does not equal a specific value. Somethin= g like: >>>> >>>> select distinct testname where result <> 'PASS"; #i.e., only the = FAIL or WARN tests >>>> >>>> I've tried several different variants like "!~", "not like ('PASS')", = "is distinct from 'PASS'", and >>>> so forth, but obviously I'm missing something as every row is being ou= tput not >>>> just the ones which do not equal PASS. What would be the correct synta= x for this in a 9.4.4 database? >>> Could it be that there are spaces or other invisible characters in the = "result" attribute? >> I'm not in front of that server at the moment, so I can't test anything = else, but I should have >> explained that the result field is char(4) not null, and all the values = in it are length(4), so no >> padding should exist. I'll try some of these once I get back home today,= but what had me concerned is >> if I entered result =3D 'PASS', as opposed to anything like not equal, t= he query worked as expected, and >> Albe, I believe the wrong syntax was just my typo from reentering it for= the email. Also, David, the >> reason I was I searching for anything other than the value 'PASS' is the= field has values of 'FAIL' or >> a 4 digit hex code produced by the instrumentation generating the data. = I sure didn't want to have to >> list every possible 4 digit hex value that is a possibility. Sorry I was= n't very clear in my first >> posting. I had been struggling with this for some time, and my temper wa= s a little short. > Well, it works for me: > > test=3D> CREATE TABLE test (id integer PRIMARY KEY, val character(4)); > CREATE TABLE > test=3D> INSERT INTO test VALUES (1, 'PASS'); > INSERT 0 1 > test=3D> INSERT INTO test VALUES (2, 'FAIL'); > INSERT 0 1 > test=3D> INSERT INTO test VALUES (3, 'PASS'); > INSERT 0 1 > test=3D> INSERT INTO test VALUES (4, 'STHG'); > INSERT 0 1 > test=3D> SELECT * FROM test WHERE val <> 'PASS'; > id | val > ----+------ > 2 | FAIL > 4 | STHG > (2 rows) > > Please double check your data. > Are they all ASCII? Any chance that there might be weird characters? > > Yours, > Laurenz Albe Thanks Laurenz, I'm believing something here may be something incorrect with my setup, but = here's the output from \d+ results Table "public.results" Column | Type | Modifiers | Storage = | Stats target | Description instrument | character varying(10) | not null | extended | = | date | character varying(15) | not null | extended | = | result | character(4) | not null | extended = | | The table has six rows: Instrument | date | result -----------------+-------------------+---------- visc100 | 01/01/2015 | PASS visc60 | 01/01/2015 | FAIL visc60pre | 01/01/2015 | 6FB3 visc60post | 01/01/2015 | 7F5A density | 01/01/2015 | PASS base | 01/01/2015 | PASS The last query I ran was: SELECT * FROM results where result <> 'PASS'; and it produced all the rows, not just the ones beginning with visc60 that = I expected. Based on what you had written, I should have seen the correct o= utput. So, any ideas? -- Jay --=20 Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-admin