From: | skinner(at)britvault(dot)co(dot)uk (Craig R(dot) Skinner) |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Number of days in a tstzrange? |
Date: | 2013-10-29 11:34:50 |
Message-ID: | 20131029113450.GA26067@teak.britvault.co.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On 2013-10-24 Thu 17:00 PM |, Jonathan S. Katz wrote:
>
> Yes, you would have to call lower() and upper() to accomplish that.
>
Here's my final solution inside a function's CUSROR LOOP:
DECLARE
billable_days integer;
...
..
BEGIN
...
...
SELECT
-- cast boundries to date
-- date - date = integer
upper(billable_item.billable_period)::date -
lower(billable_item.billable_period)::date
INTO
billable_days;
-- if a subscription is ceased same day it's started,
-- that day is still chargable, so bump it
IF billable_days < 1
THEN
billable_days := 1;
END IF;
...
...
Thanks,
--
Craig Skinner | http://twitter.com/Craig_Skinner | http://linkd.in/yGqkv7
From | Date | Subject | |
---|---|---|---|
Next Message | M. D. | 2013-10-29 13:19:22 | Re: Re: sum of until (running balance) and sum of over date range in the same query |
Previous Message | David Johnston | 2013-10-29 04:17:18 | Re: sum of until (running balance) and sum of over date range in the same query |