Conversation
Sqlite sorting is by default case sensitive. Postgres & mysql seem to be case insensitive without a common sql way to for case sensitive sorting.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #923 +/- ##
==========================================
+ Coverage 78.70% 78.78% +0.07%
==========================================
Files 57 57
Lines 2517 2526 +9
==========================================
+ Hits 1981 1990 +9
Misses 397 397
Partials 139 139 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
eternal-flame-AD
left a comment
There was a problem hiding this comment.
For Postgres and Mysql it's case insensitive which breaks fractional sorting.
That doesn't sound right, I tried on postgres and it seems to be case sensitive, am I missing something?
gotify=# select * from applications order by sort_key asc;
3 | AbVEBAyV6LKUcDL | 1 | test3 | | f | |
0 | | a0V
4 | ANE_hnibLVDWzWX | 1 | test4 | | f | |
0 | | a0l
2 | A9Iy-DqWEPvrS1k | 1 | test2 | | f | |
0 | | a1
1 | A-0KhQKUv33Q9GI | 1 | test1 | | f | |
0 | | a2
| } | ||
|
|
||
| var apps []*model.Application | ||
| if err := db.Order("user_id, sort_key, id ASC").Find(&apps).Error; err != nil && err != gorm.ErrRecordNotFound { |
There was a problem hiding this comment.
Does this not work on MySQL ?
There was a problem hiding this comment.
It should work, but given that there is a check before that the sort_key is null, it shouldn't be needed, and as the sort_key sorting can be inconsistent between database engines, I'd rather remove this.
| @@ -40,10 +42,14 @@ func (d *GormDatabase) CreateApplication(application *model.Application) error { | |||
| return d.DB.Transaction(func(tx *gorm.DB) error { | |||
| if application.SortKey == "" { | |||
There was a problem hiding this comment.
That doesn't sound right, I tried on postgres and it seems to be case sensitive, am I missing something?
Your example seems sorted case insensitive. Here a more explicit example:
psql (18.1, server 18.2 (Debian 18.2-1.pgdg13+1))
Type "help" for help.
gotify=# create table test (sort_key text not null); insert into test values ('a0V'), ('a0l'), ('a1'), ('Zz'), ('a0A');
CREATE TABLE
INSERT 0 5
gotify=# select * from test order by sort_key asc;
sort_key
----------
a0A
a0l
a0V
a1
Zz
(5 rows)
a0l is between a0A and a0V, but should actually be sorted like this:
$ python
Python 3.14.2 (main, Jan 2 2026, 14:27:39) [GCC 15.2.1 20251112] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a = ['a0V', 'a0l', 'a1', 'a0A', 'a2', 'Zz']
>>> a.sort()
>>> a
['Zz', 'a0A', 'a0V', 'a0l', 'a1', 'a2']
(using docker.io/postgres:18)
This PR fixes the sort_key index creation reported in #920 and sorting in general, as it was broken for MySQL and Postgres. ORDER BY isn't consistently implemented by Sqlite, Postgres and Mysql. For Postgres and Mysql it's case insensitive which breaks fractional sorting.
Fixes #920