Skip to content

Instantly share code, notes, and snippets.

@knubie
Last active August 16, 2016 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knubie/376cf05bb9a0e3085fa2b19a3d4f280e to your computer and use it in GitHub Desktop.
Save knubie/376cf05bb9a0e3085fa2b19a3d4f280e to your computer and use it in GitHub Desktop.
CREATE OR REPLACE FUNCTION days_remaining(users)
RETURNS interval AS $$
SELECT (start_date + (commitment_term * '1 month'::INTERVAL)) - current_date FROM users JOIN memberships ON ($1.id = memberships.user_id)
$$ STABLE LANGUAGE SQL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment