Skip to content

Commit

Permalink
Fix SQL expressions breaking subscriber export. Closes #408
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Jul 25, 2021
1 parent af11a17 commit fb48477
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fb48477

Please sign in to comment.