Files
lincodex/backend/db/queries/invitation_pending.sql
T

12 lines
537 B
SQL

-- Counts the invitations of one organization need that wait for an answer:
-- delivered, viewed, or the planned counter offer. The send counts them under
-- the organization lock, which every send takes first, so no other send can
-- add a waiting invitation between the count and its own delivery.
-- name: CountPendingNeedInvitations :one
SELECT count(*)::bigint AS pending
FROM invitations
WHERE
organization_id = sqlc.arg(organization_id)
AND need_id = sqlc.arg(need_id)
AND state IN ('delivered', 'viewed', 'counter');