pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Felix Ableitner <me@nutomic.com>
To: pgsql-general@lists.postgresql.org
Subject: SQL queries not matching on certain fields
Date: Wed, 3 Apr 2019 15:06:03 +0200
Message-ID: <084039d1-bddb-2fc6-1ad3-4be7562fd9bb@nutomic.com> (raw)

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:

|SELECTid, "preferredUsername"FROMactor
WHEREtrim("preferredUsername")='mailab';||SELECTid, "preferredUsername"FROMactor WHERE"preferredUsername"ILIKE
'mailab';|
|||SELECTid, "preferredUsername"FROMactor
WHEREmd5("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

view thread (3+ messages)  latest in thread

Message-ID: <084039d1-bddb-2fc6-1ad3-4be7562fd9bb@nutomic.com>
Permalink:  ../084039d1-bddb-2fc6-1ad3-4be7562fd9bb@nutomic.com/
Also on:    postgresql.org/message-id/084039d1-bddb-2fc6-1ad3-4be7562fd9bb@nutomic.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: me@nutomic.com
  Subject: Re: SQL queries not matching on certain fields
  In-Reply-To: <084039d1-bddb-2fc6-1ad3-4be7562fd9bb@nutomic.com>
  References: <084039d1-bddb-2fc6-1ad3-4be7562fd9bb@nutomic.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox