Skip to content

Instantly share code, notes, and snippets.

@cjpartridgeb
Created March 6, 2013 06:03
Show Gist options
  • Save cjpartridgeb/5097086 to your computer and use it in GitHub Desktop.
Save cjpartridgeb/5097086 to your computer and use it in GitHub Desktop.
SELECT subscriptions.id, subscriptions.agency_id, subscriptions.expiry,
CASE
WHEN subscriptions.expiry > date_part('epoch'::text, now())::bigint THEN 'current'::text
ELSE 'expired'::text
END AS status
FROM subscriptions
ORDER BY subscriptions.expiry DESC;
-- This returns:
-- 25;1;1394321699;"current"
-- 25;1;1394321627;"current"
-- 23;1;1361057708;"expired"
-- 26;1;1296767409;"expired"
-- Is there an easy way to return "current" for the actual current, and "future" for any after
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment