I cannot understand the behavior of PostgreSQL (v11.10). Here is what I do:
create temp table test (first_name text, last_name text);
insert into test values
('Hanna', 'Beat'),
('JOAN', 'BEET'),
('Mark', 'Bernstein'),
('ALFRED', 'DOE'),
('henry', 'doe'),
('Henry', 'Doe'),
('Dennis', 'Doe');
select last_name, first_name from test order by last_name, first_name;
This is what I get.
last_name | first_name
-----------+------------
Beat | Hanna
BEET | JOAN
Bernstein | Mark
doe | henry
Doe | Dennis
Doe | Henry
DOE | ALFRED
(7 rows)
It looks like the sorting of the first three names is case-insensitive, but for the last four it's case-sensitive. Why is that so?
In other words, if the sorting were case-sensitive, I would expect the following order:
last_name | first_name
-----------+------------
Beat | Hanna
Bernstein | Mark
BEET | JOAN
doe | henry
Doe | Dennis
Doe | Henry
DOE | ALFRED
(7 rows)
and if it were case-insensitive, I would expect this:
last_name | first_name
-----------+------------
Beat | Hanna
BEET | JOAN
Bernstein | Mark
DOE | ALFRED
Doe | Dennis
doe | henry
Doe | Henry
(7 rows)
What I get instead is a mixture of both, and that baffles me...
For completeness:
# show lc_collate; show lc_ctype;
lc_collate
-------------
en_US.UTF-8
(1 row)
lc_ctype
-------------
en_US.UTF-8
(1 row)
Beat, thenBernstein, thenBEET. I edited the question to make it more clear.aAbBcCdDeEfF..., notabcdef...ABCDEForABCDEF...abcdef. Demoa <<< A << à <<< À < b <<< B