Back to Blog

Why Your AI's Active Subscribers Are the Ones Who Already Cancelled

Asked for active subscriptions and got 30. Those 30 have a cancel date in the future. The other 1,170 are still active because ended_at is NULL, and NULL > now() is not true, so they were dropped.

You ask: "How many active subscriptions do we have?" The AI says 30. The table has 1,200 rows. 1,170 have no ended_at. 30 have an ended_at next month. 80 already ended.

SELECT COUNT(*)
FROM subscriptions
WHERE ended_at > now()

The 30 are people who cancelled and are paid through a future date. The 1,170 are the normal active rows: no end has been set. NULL > now() is unknown, not true, so those rows never pass the WHERE. The count you got is the cancellation queue.

NULL here means "no end," and a comparison cannot see it

A date comparison only keeps rows where the test is true. NULL is not true. So "still going" stored as NULL is invisible to ended_at > now(), ended_at >= '2026-03-01', and ended_at BETWEEN ....

-- active right now: open-ended, or ended later
SELECT COUNT(*)
FROM subscriptions
WHERE ended_at IS NULL
   OR ended_at > now()

-- active at any point in March 2026
SELECT COUNT(*)
FROM subscriptions
WHERE started_at < TIMESTAMPTZ '2026-04-01'
  AND (ended_at IS NULL OR ended_at >= TIMESTAMPTZ '2026-03-01')

The first query returns 1,200, including the 30 who have given notice. If "active" for you means "has not asked to cancel," count only ended_at IS NULL and say that. Either definition is usable. ended_at > now() alone is neither one.

This is the same rule as a != filter dropping NULL statuses, pointed at a range. It is not a soft delete left in the count. There the missing filter adds tombstones. Here the comparison removes the live rows and leaves the ones with a date filled in.

Check the convention before you add IS NULL. Some schemas store "no end" as 2099-01-01 instead of NULL. Those rows already satisfy ended_at > now().

How to catch it

SELECT
  COUNT(*) FILTER (WHERE ended_at IS NULL)     AS open_ended,
  COUNT(*) FILTER (WHERE ended_at > now())     AS ends_later,
  COUNT(*) FILTER (WHERE ended_at <= now())    AS already_ended
FROM subscriptions

If open_ended is almost the whole table and the AI's active count equals ends_later, the query kept the scheduled cancellations and dropped everyone else. Add open_ended to that count and you have the people who are still paid up.

The prompt that heads this off

When I ask for active subscriptions, plans, or anything with a start and
an end, look at ended_at first. If NULL means "no end," active is
ended_at IS NULL OR ended_at > now(). Do not write ended_at > now() alone.
Show me the open-ended count, the future-end count, and the already-ended
count next to the number you report.

The short version

ended_at > now() keeps people who cancel later and drops people whose end was never set. NULL means still active. Write IS NULL OR ended_at > now(), and say whether the future cancellations are included.


Read-only MCP gateway: mcpserver.design.

Related reading: