Thread: make_interval ??

make_interval ??

From
Pavel Stehule
Date:
Hello

we have defined interface date, time, timestamp constructors.

There is a question if we would to have some similar for interval type?

As different from time, timestamp there we can use a zero as defaults.

So constructor should to look like:

CREATE OR REPLACE FUNCTION make_interval(years int DEFAULT 0, months int DEFAULT 0, ...)

and usage:

SELECT make_interval(years := 2)
SELECT make_interval(days := 14)

Is there a interest for this (or similar) function?

Regards

Pavel

Re: make_interval ??

From
Josh Berkus
Date:
Pavel,

> So constructor should to look like:
> 
> CREATE OR REPLACE FUNCTION make_interval(years int DEFAULT 0, months int
> DEFAULT 0, ...)
> 
> and usage:
> 
> SELECT make_interval(years := 2)
> SELECT make_interval(days := 14)
> 
> Is there a interest for this (or similar) function?

It would certainly make our Python users happy.

And for that matter would get rid of this kind of stupid thing in stored
procedure code:

time_ahead := ( interval '1 minute' * var_skip );

So, +1 for the feature.

-- 
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com



Re: make_interval ??

From
Gavin Flower
Date:
On 21/12/13 06:29, Josh Berkus wrote:
> Pavel,
>
>> So constructor should to look like:
>>
>> CREATE OR REPLACE FUNCTION make_interval(years int DEFAULT 0, months int
>> DEFAULT 0, ...)
>>
>> and usage:
>>
>> SELECT make_interval(years := 2)
>> SELECT make_interval(days := 14)
>>
>> Is there a interest for this (or similar) function?
> It would certainly make our Python users happy.
>
> And for that matter would get rid of this kind of stupid thing in stored
> procedure code:
>
> time_ahead := ( interval '1 minute' * var_skip );
>
> So, +1 for the feature.
>
What about leap years?

Cheers,
Gavin




Re: make_interval ??

From
Josh Berkus
Date:
On 12/20/2013 03:09 PM, Gavin Flower wrote:
> What about leap years?

What about them?

-- 
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com



Re: make_interval ??

From
Gavin Flower
Date:
On 21/12/13 13:40, Josh Berkus wrote:
> On 12/20/2013 03:09 PM, Gavin Flower wrote:
>> What about leap years?
> What about them?
>
some years have 365 days others have 366, so how any days in an interval 
of 2 years?, 4 years?



Re: make_interval ??

From
Josh Berkus
Date:
On 12/20/2013 04:44 PM, Gavin Flower wrote:
> On 21/12/13 13:40, Josh Berkus wrote:
>> On 12/20/2013 03:09 PM, Gavin Flower wrote:
>>> What about leap years?
>> What about them?
>>
> some years have 365 days others have 366, so how any days in an interval
> of 2 years?, 4 years?

Your question isn't relevant to this patch.  It's not defining the
interval type, just creating an alternate constructor for it.

(the answer is, it depends on what timestamp you're adding it to ...)

-- 
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com



Re: make_interval ??

From
Pavel Stehule
Date:
Hello

here is patch

postgres=# select make_interval(years := 1, months := 6);
 make_interval
---------------
 1 year 6 mons
(1 row)

postgres=# select make_interval(weeks := 3);
 make_interval
---------------
 21 days
(1 row)

postgres=# select make_interval(days := 10);
 make_interval
---------------
 10 days
(1 row)

postgres=# select make_interval(hours := 2, mins := 10, secs := 25.33);
 make_interval
---------------
 02:10:25.33
(1 row)

Regards

Pavel


2013/12/21 Josh Berkus <josh@agliodbs.com>
On 12/20/2013 04:44 PM, Gavin Flower wrote:
> On 21/12/13 13:40, Josh Berkus wrote:
>> On 12/20/2013 03:09 PM, Gavin Flower wrote:
>>> What about leap years?
>> What about them?
>>
> some years have 365 days others have 366, so how any days in an interval
> of 2 years?, 4 years?

Your question isn't relevant to this patch.  It's not defining the
interval type, just creating an alternate constructor for it.

(the answer is, it depends on what timestamp you're adding it to ...)

--
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com


--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Attachment