Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hBfaw-0005oi-N9 for pgsql-general@arkaria.postgresql.org; Wed, 03 Apr 2019 13:06:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hBfav-0001wp-1S for pgsql-general@arkaria.postgresql.org; Wed, 03 Apr 2019 13:06:21 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hBfau-0001wi-Kb for pgsql-general@lists.postgresql.org; Wed, 03 Apr 2019 13:06:20 +0000 Received: from mx1.mailbox.org ([2001:67c:2050:104:0:1:25:1]) by makus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hBfar-0000xb-5g for pgsql-general@lists.postgresql.org; Wed, 03 Apr 2019 13:06:19 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx1.mailbox.org (Postfix) with ESMTPS id CD7A84C45F for ; Wed, 3 Apr 2019 15:06:10 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by hefe.heinlein-support.de (hefe.heinlein-support.de [91.198.250.172]) (amavisd-new, port 10030) with ESMTP id 7gJtWC1XsSVk for ; Wed, 3 Apr 2019 15:06:05 +0200 (CEST) From: Felix Ableitner To: pgsql-general@lists.postgresql.org Openpgp: preference=signencrypt Autocrypt: addr=me@nutomic.com; prefer-encrypt=mutual; keydata= mQENBFJ2ZSwBCADPn4dJvg0qfj8iBLQnyNniuNyfrxWQS6l7H6X3dKmX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yy2kTs4fXpnxHq6CWGskkQ5puQ6 YFUzEmoyQEpSzOyBw6IZEFYqkR+Oen8D7QARAQABiQEfBBgBAgAJBQJSdmUsAhsMAAoJEL8A Yyls7jfGiaEIAKDRiEpT2WbJcZy1NkqC1ya/MXXDZPmQFQJld5x7cpOSiFlTCwzrSmSaTNEw K2/zRtmywImGFlMyNAsKWPfEOuefBHRQj4DW7fCARxo5I1Ms8t/91Q7q14Ra/nLwB3LT9KZN bQZ0V11xifgtDfUtTBsBrhCdzxTL7Fp5eOnSBaDkRiKOLG43AL2MOro7VH1sALiEA1+j2yR2 weqy7eNANMUFKQv/Ste2yZ3i8SFZJcZeKLAcZKImOMinteKFsnZsF+ojjGsdhiyWApbu2dMg 0O9HcN+DiAlhpJcX+bRlWgdowJChwfkGhsW9edUfxDWoZCdqRp549ou+2j/tATpwamE= Subject: SQL queries not matching on certain fields Message-ID: <084039d1-bddb-2fc6-1ad3-4be7562fd9bb@nutomic.com> Date: Wed, 3 Apr 2019 15:06:03 +0200 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="------------00E4C2C610D41DAC31825EB2" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------00E4C2C610D41DAC31825EB2 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello, I'm having a very strange problem with the Postgres database for my website. Some SQL queries are not matching on certain fields. I am running these commands via the psql command. Here is a query that works as expected: # SELECT id, "preferredUsername" FROM actor WHERE "preferredUsername"=3D'= emma'; id=C2=A0=C2=A0 | preferredUsername -------+------------------- 48952 | emma 58672 | emma (2 rows) The following query should work as well, because the username exists. But in fact, it consistently returns nothing: # SELECT id, "preferredUsername" FROM actor WHERE "preferredUsername"=3D'= mailab'; id | preferredUsername ----+------------------- (0 rows) There are some workarounds which fix the WHERE statement, all of the following work as expected: |SELECTid, "preferredUsername"FROMactor WHEREtrim("preferredUsername")=3D'mailab';||SELECTid, "preferredUsername"= FROMactor WHERE"preferredUsername"ILIKE 'mailab';| |||SELECTid, "preferredUsername"FROMactor WHEREmd5("preferredUsername")=3Dmd5('mailab');| || Now you might think that there is something wrong with the encoding, or the field contains some extra whitespace. But SHOW SERVER_ENCODING and SHOW SERVER_ENCODING show UTF8. Length and m5 sum are also exactly as expected. And I checked the individual bytes with get_byte(), all of them are in the range 97-122. About the setup, this is Postgres 10 running in Docker, on an Ubuntu VPS (see below for all versions etc). I had this problem before on the same setup, so I did an export to text file with pg_dump, and imported into a completely new database with psql. That fixed the problem for a few days, but it came back soon after. The problem only seems to affect one or two specific columns, and only a few specific rows in those columns. Most other rows work normally. Affected columns also randomly start working again after a few days, and other columns get affected. I havent noticed any kind of pattern. You can find the table definition here: https://gitlab.com/snippets/18403= 20 Version info: Postgres Docker Image: postgres:10.7-alpine Docker version: 18.09.2 OS: Ubuntu 18.04.2 Please tell me if you have any idea how to fix or debug this. I already asked multiple people, and no one has a clue what is going on. Best, Felix Ableitner --------------00E4C2C610D41DAC31825EB2 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

Hello,

I'm having a very strange problem with the Postgres database for my website. Some SQL queries are not matching on certain fields. I am running these commands via the psql command.

Here is a query that works as expected:

# SELECT id, "preferredUsername" FROM actor WHERE "preferredUsername"='emma';
  id   | preferredUsername
-------+-------------------
 48952 | emma
 58672 | emma
(2 rows)

The following query should work as well, because the username exists. But in fact, it consistently returns nothing:

# SELECT id, "preferredUsername" FROM actor WHERE "preferredUsername"='mailab';
 id | preferredUsername
----+-------------------

      (0 rows)

There are some workarounds which fix the WHERE statement, all of the following work as expected:

SELECT id, "preferredUsername" FROM actor WHERE trim("preferredUsername")='mailab';

SELECT id, "preferredUsername" FROM actor WHERE "preferredUsername" ILIKE 'mailab'; 

SELECT id, "preferredUsername" FROM actor WHERE md5("preferredUsername")=md5('mailab'); 


Now you might think that there is something wrong with the encoding, or the field contains some extra whitespace. But SHOW SERVER_ENCODING and SHOW SERVER_ENCODING show UTF8. Length and m5 sum are also exactly as expected. And I checked the individual bytes with get_byte(), all of them are in the range 97-122.

About the setup, this is Postgres 10 running in Docker, on an Ubuntu VPS (see below for all versions etc). I had this problem before on the same setup, so I did an export to text file with pg_dump, and imported into a completely new database with psql. That fixed the problem for a few days, but it came back soon after.

The problem only seems to affect one or two specific columns, and only a few specific rows in those columns. Most other rows work normally. Affected columns also randomly start working again after a few days, and other columns get affected. I havent noticed any kind of pattern.

You can find the table definition here: https://gitlab.com/snippets/1840320

Version info:

Postgres Docker Image: postgres:10.7-alpine
Docker version: 18.09.2
OS: Ubuntu 18.04.2

Please tell me if you have any idea how to fix or debug this. I already asked multiple people, and no one has a clue what is going on.

Best,
Felix Ableitner

--------------00E4C2C610D41DAC31825EB2--