Skip to content

Commit

Permalink
Fix next-campaigns query to return campaign_ids with 0 counts as well…
Browse files Browse the repository at this point in the history
… when there were 0 subscribers in target_lists. This would result in started_at never being updated in the update sub query.
  • Loading branch information
knadh committed Nov 1, 2018
1 parent d712aff commit 1473961
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ WITH camps AS (
),
counts AS (
-- For each campaign above, get the total number of subscribers and the max_subscriber_id across all its lists.
SELECT campaign_id, COUNT(subs.id) as to_send, COALESCE(MAX(subs.id), 0) as max_subscriber_id
FROM subscribers subs, subscriber_lists sublists, campaign_lists camplists
WHERE sublists.list_id = camplists.list_id AND
subs.id = sublists.subscriber_id
AND camplists.campaign_id = ANY(SELECT id FROM camps)
GROUP BY camplists.campaign_id
SELECT id AS campaign_id, COUNT(subscriber_lists.subscriber_id) AS to_send,
COALESCE(MAX(subscriber_lists.subscriber_id), 0) AS max_subscriber_id FROM camps
LEFT JOIN campaign_lists ON (campaign_lists.campaign_id = camps.id)
LEFT JOIN subscriber_lists ON (subscriber_lists.list_id = campaign_lists.list_id)
WHERE campaign_lists.campaign_id = ANY(SELECT id FROM camps)
GROUP BY camps.id
),
u AS (
-- For each campaign above, update the to_send count.
Expand Down

0 comments on commit 1473961

Please sign in to comment.