From d712afff97f3ab4569d0000cb50d6848e91384aa Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Thu, 1 Nov 2018 17:50:03 +0530 Subject: [PATCH] Fix error on campaign creation when there are 0 target in target lists --- queries.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/queries.sql b/queries.sql index 1aec414..a87a813 100644 --- a/queries.sql +++ b/queries.sql @@ -132,7 +132,7 @@ DELETE FROM lists WHERE id = ALL($1); -- name: create-campaign -- This creates the campaign and inserts campaign_lists relationships. WITH counts AS ( - SELECT COUNT(id) as to_send, MAX(id) as max_sub_id + SELECT COALESCE(COUNT(id), 0) as to_send, COALESCE(MAX(id), 0) as max_sub_id FROM subscribers LEFT JOIN subscriber_lists ON (subscribers.id = subscriber_lists.subscriber_id) WHERE subscriber_lists.list_id=ANY($11::INT[]) @@ -143,7 +143,6 @@ camp AS ( SELECT $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, (SELECT to_send FROM counts), (SELECT max_sub_id FROM counts) - WHERE (SELECT COALESCE(MAX(to_send), 0) FROM counts) > 0 RETURNING id ) INSERT INTO campaign_lists (campaign_id, list_id, list_name)