fix sql query

This commit is contained in:
Abhinav Raut
2025-05-25 11:02:00 +05:30
parent 9226063db3
commit 8ad2f078ac
+4 -4
View File
@@ -75,9 +75,9 @@ SET next_sla_deadline_at = CASE
-- If resolved or closed, clear the deadline
WHEN c.status_id IN (SELECT id FROM conversation_statuses WHERE name IN ('Resolved', 'Closed')) THEN NULL
-- If an external timestamp ($3) is provided (e.g. next_response), use the earliest of $3.
WHEN $3 IS NOT NULL THEN LEAST(
$3::TIMESTAMPTZ,
-- If an external timestamp ($2) is provided (e.g. next_response), use the earliest of $2.
WHEN $2::TIMESTAMPTZ IS NOT NULL THEN LEAST(
$2::TIMESTAMPTZ,
CASE
WHEN c.first_reply_at IS NOT NULL AND c.resolved_at IS NULL AND a.resolution_deadline_at IS NOT NULL THEN a.resolution_deadline_at
WHEN c.first_reply_at IS NULL AND c.resolved_at IS NULL AND a.first_response_deadline_at IS NOT NULL THEN a.first_response_deadline_at
@@ -86,7 +86,7 @@ SET next_sla_deadline_at = CASE
END
)
-- No $3,
-- No $2,
ELSE CASE
WHEN c.first_reply_at IS NOT NULL AND c.resolved_at IS NULL AND a.resolution_deadline_at IS NOT NULL THEN a.resolution_deadline_at
WHEN c.first_reply_at IS NULL AND c.resolved_at IS NULL AND a.first_response_deadline_at IS NOT NULL THEN a.first_response_deadline_at