From fb48477aa71f351a07e8f17d6d5f7c0b4025d3b2 Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Sun, 25 Jul 2021 22:42:54 +0530 Subject: [PATCH] Fix SQL expressions breaking subscriber export. Closes #408 --- queries.sql | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/queries.sql b/queries.sql index e7f7ed7..59cab9b 100644 --- a/queries.sql +++ b/queries.sql @@ -249,16 +249,24 @@ SELECT COUNT(*) OVER () AS total, subscribers.* FROM subscribers -- Unprepared statement for issuring arbitrary WHERE conditions for -- searching subscribers to do bulk CSV export. -- %s = arbitrary expression -SELECT s.id, s.uuid, s.email, s.name, s.status, s.attribs, s.created_at, s.updated_at FROM subscribers s +SELECT subscribers.id, + subscribers.uuid, + subscribers.email, + subscribers.name, + subscribers.status, + subscribers.attribs, + subscribers.created_at, + subscribers.updated_at + FROM subscribers LEFT JOIN subscriber_lists sl ON ( -- Optional list filtering. (CASE WHEN CARDINALITY($1::INT[]) > 0 THEN true ELSE false END) - AND sl.subscriber_id = s.id + AND sl.subscriber_id = subscribers.id ) WHERE sl.list_id = ALL($1::INT[]) AND id > $2 %s - ORDER BY s.id ASC LIMIT (CASE WHEN $3 = 0 THEN NULL ELSE $3 END); + ORDER BY subscribers.id ASC LIMIT (CASE WHEN $3 = 0 THEN NULL ELSE $3 END); -- name: query-subscribers-template -- raw: true