pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #14944: Error for 6 digit year in date comparision
3+ messages / 3 participants
[nested] [flat]

* BUG #14944: Error for 6 digit year in date comparision
@ 2017-12-04 09:18  abedi0501@gmail.com
  0 siblings, 1 reply; 3+ messages in thread

From: abedi0501@gmail.com @ 2017-12-04 09:18 UTC (permalink / raw)
  To: pgsql-bugs; +Cc: abedi0501@gmail.com

The following bug has been logged on the website:

Bug reference:      14944
Logged by:          Akash Bedi
Email address:      abedi0501@gmail.com
PostgreSQL version: 9.5.4
Operating system:   Ubuntu 16/Windows 10
Description:        

I'm noticing errors during date comparison, 

--Below works fine
select '99999-01-01'::date > now();
?column?
----------
 t
(1 row)

--Gives error
select '999999-01-01'::date > now();
ERROR:  date out of range for timestamp

Database allows to store date ranges until 5874897 AD '5874897-01-01'::date
but date comparison fails.
 



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #14944: Error for 6 digit year in date comparision
@ 2017-12-04 10:45  Francisco Olarte <folarte@peoplecall.com>
  parent: abedi0501@gmail.com
  0 siblings, 1 reply; 3+ messages in thread

From: Francisco Olarte @ 2017-12-04 10:45 UTC (permalink / raw)
  To: abedi0501@gmail.com; +Cc: pgsql-bugs

On Mon, Dec 4, 2017 at 10:18 AM,  <abedi0501@gmail.com> wrote:
> I'm noticing errors during date comparison,
> --Below works fine
> select '99999-01-01'::date > now();
> ?column?
> ----------
>  t
> (1 row)
> --Gives error
> select '999999-01-01'::date > now();
> ERROR:  date out of range for timestamp
>
> Database allows to store date ranges until 5874897 AD '5874897-01-01'::date
> but date comparison fails.

Seems a failure in reading comprehension, more than a bug. Notice the
error you pasted it says "out of range FOR TIMESTAMP"

When comparing dates to timestamps dates are converted to timestamp,
the greater precision type, because otherwise you would get erroneous
results. Not in your particular case ( as conversion to date truncates
down ) but it would in the other sense:

2017-01-01::date < 2017-01-01 10:00:00 timestamp > true => date is
upgraded adding 00:00:00

If you convert timestmap to date it would be false ( they would be equal ).

if you read https://www.postgresql.org/docs/10/static/datatype-datetime.html
you'll notice year in timestamps only covers 4713 BC to 294276 AD.

Cast now() to date or use current_date to avoid that:

test=> select '999999-01-01'::date;
     date
--------------
 999999-01-01
(1 row)

test=> select '999999-01-01'::date::timestamp;
ERROR:  date out of range for timestamp
test=> select '999999-01-01'::date > now();
ERROR:  date out of range for timestamp
test=> select '999999-01-01'::date > now()::date;
 ?column?
----------
 t
(1 row)

test=> select '999999-01-01'::date > current_date, current_date;
 ?column? |    date
----------+------------
 t        | 2017-12-04
(1 row)

Francisco Olarte.




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #14944: Error for 6 digit year in date comparision
@ 2017-12-04 10:53  Akash Bedi <abedi0501@gmail.com>
  parent: Francisco Olarte <folarte@peoplecall.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Akash Bedi @ 2017-12-04 10:53 UTC (permalink / raw)
  To: Francisco Olarte <folarte@peoplecall.com>; +Cc: pgsql-bugs

Thanks for the clarification.

On Mon, Dec 4, 2017 at 4:15 PM, Francisco Olarte <folarte@peoplecall.com>
wrote:

> On Mon, Dec 4, 2017 at 10:18 AM,  <abedi0501@gmail.com> wrote:
> > I'm noticing errors during date comparison,
> > --Below works fine
> > select '99999-01-01'::date > now();
> > ?column?
> > ----------
> >  t
> > (1 row)
> > --Gives error
> > select '999999-01-01'::date > now();
> > ERROR:  date out of range for timestamp
> >
> > Database allows to store date ranges until 5874897 AD
> '5874897-01-01'::date
> > but date comparison fails.
>
> Seems a failure in reading comprehension, more than a bug. Notice the
> error you pasted it says "out of range FOR TIMESTAMP"
>
> When comparing dates to timestamps dates are converted to timestamp,
> the greater precision type, because otherwise you would get erroneous
> results. Not in your particular case ( as conversion to date truncates
> down ) but it would in the other sense:
>
> 2017-01-01::date < 2017-01-01 10:00:00 timestamp > true => date is
> upgraded adding 00:00:00
>
> If you convert timestmap to date it would be false ( they would be equal ).
>
> if you read https://www.postgresql.org/docs/10/static/datatype-
> datetime.html
> you'll notice year in timestamps only covers 4713 BC to 294276 AD.
>
> Cast now() to date or use current_date to avoid that:
>
> test=> select '999999-01-01'::date;
>      date
> --------------
>  999999-01-01
> (1 row)
>
> test=> select '999999-01-01'::date::timestamp;
> ERROR:  date out of range for timestamp
> test=> select '999999-01-01'::date > now();
> ERROR:  date out of range for timestamp
> test=> select '999999-01-01'::date > now()::date;
>  ?column?
> ----------
>  t
> (1 row)
>
> test=> select '999999-01-01'::date > current_date, current_date;
>  ?column? |    date
> ----------+------------
>  t        | 2017-12-04
> (1 row)
>
> Francisco Olarte.
>

^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2017-12-04 10:53 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-12-04 09:18 BUG #14944: Error for 6 digit year in date comparision abedi0501@gmail.com
2017-12-04 10:45 ` Francisco Olarte <folarte@peoplecall.com>
2017-12-04 10:53   ` Akash Bedi <abedi0501@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox