From 459ede2b7ebcbbc85135c65991768334b460358e Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Tue, 13 May 2025 22:28:34 +0200 Subject: Fix SQL request for user labels with custom sort (#7588) The list or articles with a user label with a custom sort was broken when using PostgreSQL Example: `https://freshrss.example.net/i/?a=normal&get=T&sort=title&order=ASC` ``` SQL error FreshRSS_EntryDAO::listWhereRaw["42P10",7,"ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list\nLINE 3: ...d_entry = e.id WHERE 1=1 AND e.id <= $1 ORDER BY e.title DE...\n ^"] ``` --- app/Models/EntryDAO.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'app/Models') diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php index f9dc9fd82..af859045d 100644 --- a/app/Models/EntryDAO.php +++ b/app/Models/EntryDAO.php @@ -1318,7 +1318,9 @@ SQL; return [array_merge($values, $searchValues), 'SELECT ' . ($type === 'T' ? 'DISTINCT ' : '') - . 'e.id FROM `_entry` e ' + . 'e.id' + . ($type === 'T' && $orderBy !== 'e.id' ? ', ' . $orderBy : '') // SELECT DISTINCT, ORDER BY expressions must appear in SELECT + . ' FROM `_entry` e ' . 'INNER JOIN `_feed` f ON e.id_feed = f.id ' . ($type === 't' || $type === 'T' ? 'INNER JOIN `_entrytag` et ON et.id_entry = e.id ' : '') . 'WHERE ' . $where -- cgit v1.2.3