Re: 'infinity'::Interval should be added

2018-12-17 Thread Tom Lane
Isaac Morland writes: > On Mon, 17 Dec 2018 at 18:00, Tom Lane wrote: >> tl;dr: we should model it after the behavior of IEEE float infinities, >> except we'll want to throw errors where those produce NaNs. > Would it be OK to return NULL for ∞ - ∞? IMO, no. The only thing worse than inventing

Re: 'infinity'::Interval should be added

2018-12-17 Thread Isaac Morland
On Mon, 17 Dec 2018 at 18:00, Tom Lane wrote: > > so I was thinking that > > postgres=# select 'infinity'::timestamp - 'infinity'::timestamp; > > would be zero rather than an error, for least surprise. > > Wrong. This case needs to be undefined, because "infinity" > isn't a specific value. Tha

Re: 'infinity'::Interval should be added

2018-12-17 Thread Andres Freund
Hi, On 2018-12-15 11:34:10 -0800, Andres Freund wrote: > [1] We should optimize the computation using pg_add_s{32,64}_overflow, > the generated code after that change is *substantially* better (as > well as the original code much shorter, and correct). And consider, > as mentioned fur

Re: 'infinity'::Interval should be added

2018-12-17 Thread Tom Lane
Simon Riggs writes: > I would like to represent 'infinity' as interval->months = INT_MAX Per the discussion upthread, what we need when creating an infinite value is to set month = INT32_MAX, day = INT32_MAX, time = INT64_MAX (for +Infinity) month = INT32_MIN, day = INT32_MIN, time = INT64_MIN (f

Re: 'infinity'::Interval should be added

2018-12-17 Thread Chapman Flack
On 12/17/18 5:37 PM, Simon Riggs wrote: > postgres=# select 'infinity'::timestamp = 'infinity'::timestamp; > ?column? > -- > t I'm not persuaded that's a good idea, and would prefer to see an is_infinite() predicate, and an = operator that complains. But if the above is current behavior,

Re: 'infinity'::Interval should be added

2018-12-17 Thread Simon Riggs
On Mon, 17 Dec 2018 at 03:48, Tom Lane wrote: > The positive argument for adding infinity to interval is that > we define operations such as timestamp minus timestamp as > yielding interval. That's why this has to fail right now: > > regression=# select timestamp 'infinity' - timestamp 'now'; >

Re: 'infinity'::Interval should be added

2018-12-16 Thread Isaac Morland
On Sun, 16 Dec 2018 at 22:27, Robert Haas wrote: > Simon's argument for adding this is that we support 'infinity' for > timestamp, but is that a good argument for making 'interval' do it, > given that there are many other types like date for which we don't > support it? > postgres=> select 'inf

Re: 'infinity'::Interval should be added

2018-12-16 Thread Tom Lane
Robert Haas writes: > Simon's argument for adding this is that we support 'infinity' for > timestamp, but is that a good argument for making 'interval' do it, > given that there are many other types like date for which we don't > support it? My feeling is that date is to timestamp as integer is t

Re: 'infinity'::Interval should be added

2018-12-16 Thread Robert Haas
On Sat, Dec 15, 2018 at 3:02 PM Tom Lane wrote: > Andres Freund writes: > > On 2018-12-15 14:43:49 -0500, Tom Lane wrote: > >> Note that timestamp_lt etc don't actually need any special case for > >> infinity, and we could hope that the infinity representation for interval > >> makes it possible

Re: 'infinity'::Interval should be added

2018-12-15 Thread Tom Lane
Andres Freund writes: > On 2018-12-15 14:43:49 -0500, Tom Lane wrote: >> Note that timestamp_lt etc don't actually need any special case for >> infinity, and we could hope that the infinity representation for interval >> makes it possible to likewise not special-case it in interval comparisons. >>

Re: 'infinity'::Interval should be added

2018-12-15 Thread Andres Freund
Hi, On 2018-12-15 14:43:49 -0500, Tom Lane wrote: > Note that timestamp_lt etc don't actually need any special case for > infinity, and we could hope that the infinity representation for interval > makes it possible to likewise not special-case it in interval comparisons. > But I think it's silly

Re: 'infinity'::Interval should be added

2018-12-15 Thread Tom Lane
Andres Freund writes: > On 2018-12-15 09:44:50 -0500, Tom Lane wrote: >> Yes. The performance argument has some merit for cases like int4 and >> float8, where the "useful work" might be as small as one machine >> instruction. But timestamp and interval operations are, for the most >> part, prett

Re: 'infinity'::Interval should be added

2018-12-15 Thread Andres Freund
Hi, On 2018-12-15 09:44:50 -0500, Tom Lane wrote: > Simon Riggs writes: > > On Fri, 14 Dec 2018 at 22:24, Robert Haas wrote: > >> So essentially I think supporting special values like infinity boils > >> down to trading away some small amount of performance -- more likely > >> to be noticeable w

Re: 'infinity'::Interval should be added

2018-12-15 Thread Tom Lane
Simon Riggs writes: > On Fri, 14 Dec 2018 at 22:24, Robert Haas wrote: >> So essentially I think supporting special values like infinity boils >> down to trading away some small amount of performance -- more likely >> to be noticeable with JIT -- for some amount of possible programmer >> convenie

Re: 'infinity'::Interval should be added

2018-12-15 Thread Simon Riggs
On Fri, 14 Dec 2018 at 22:24, Robert Haas wrote: > So essentially I think supporting special values like infinity boils > down to trading away some small amount of performance -- more likely > to be noticeable with JIT -- for some amount of possible programmer > convenience. Some people may thi

Re: 'infinity'::Interval should be added

2018-12-14 Thread Robert Haas
On Fri, Dec 14, 2018 at 9:11 PM Tom Lane wrote: > Isaac Morland writes: > > I would be interested if you have an example where the ability of > > date/timestamp values to be infinite adds special case coding. > > I think Robert is talking about the implementation functions for > timestamp-related

Re: 'infinity'::Interval should be added

2018-12-14 Thread Tom Lane
Isaac Morland writes: > I would be interested if you have an example where the ability of > date/timestamp values to be infinite adds special case coding. I think Robert is talking about the implementation functions for timestamp-related operations, which typically do have to special-case infinit

Re: 'infinity'::Interval should be added

2018-12-14 Thread Isaac Morland
On Fri, 14 Dec 2018 at 15:16, Robert Haas wrote: > Why? I consider it somewhat of a wart that timestamps allow infinity > - it adds special case coding all over the place. Allowing intervals > to be infinite as well seems like it'll just create more special cases > without really solving anyth

Re: 'infinity'::Interval should be added

2018-12-14 Thread Robert Haas
On Thu, Dec 13, 2018 at 9:42 AM Simon Riggs wrote: > At present we have a timestamp of 'infinity' and infinite ranges, but no > infinite interval > > SELECT 'infinity'::timestamp; > works > > SELECT 'infinity'::interval; > ERROR: invalid input syntax for type interval: "infinity" > > Seems a str

Re: 'infinity'::Interval should be added

2018-12-13 Thread Tom Lane
Chapman Flack writes: > On 12/13/18 04:41, Simon Riggs wrote: >> [ we should allow this: ] >> SELECT 'infinity'::interval; >> ERROR: invalid input syntax for type interval: "infinity" > ... and if that is made to work, perhaps then arithmetic should be > updated as well, That wouldn't be option

Re: 'infinity'::Interval should be added

2018-12-13 Thread Chapman Flack
On 12/13/18 04:41, Simon Riggs wrote: > SELECT 'infinity'::timestamp; > works > > SELECT 'infinity'::interval; > ERROR: invalid input syntax for type interval: "infinity" ... and if that is made to work, perhaps then arithmetic should be updated as well, with this producing an infinite interval