I have a SQL table that looks like this (irrelevant parts excluded):
# \d users
Table "public.users"
Column | Type | Collation | Nullable | Default
----------------+-----------------------------+-----------+----------+-----------------------------------
id | integer | | not null | nextval('users_id_seq'::regclass)
name | character varying(64) | | not null |
Indexes:
"users_pkey" PRIMARY KEY, btree (id)
"users_name_key" UNIQUE CONSTRAINT, btree (name)
Now I encountered this very strange behavior, where I cannot select a specific row (of which I know it's there). However, if I use functions like trim
, lower
or also ILIKE (without wildcards) then the select works. All of those functions do not alter the value I filter for. It's already lower-case, trimmed & completely ASCII:
-- Does not work (no results returned):
SELECT * FROM users WHERE name = 'user@somedomain.com';
SELECT * FROM users WHERE name LIKE 'user@somedomain.com';
-- Works (selects the expected row):
SELECT * FROM users WHERE name LIKE '%user@somedomain.com';
SELECT * FROM users WHERE name LIKE 'user@somedomain.com%';
SELECT * FROM users WHERE name ILIKE 'user@somedomain.com';
SELECT * FROM users WHERE lower(name) = 'user@somedomain.com';
SELECT * FROM users WHERE trim(name) = 'user@somedomain.com';
Attempts to export the value as bytea
also did not show things like a nul-byte or other unprintable characters. The curious part is that the query used to work and still works on another machine that has the exact same PostgreSQL version and data (replicated from the machine that does not work). I use PostgreSQL version 14.0, as container from the official Docker Hub account (not Alpine).
Any clues?