Skip to content

[#382] Consider 0000-01-01 as invalid date

Issue

Copied from !1496 (comment 2279794765)

I notice that Octo prints a date that has the year 0000. But such a year does not exist. Postgres prints the year as 0001 BC as can be seen below.

OCTO> select timestamp '0001-01-01' - interval '1 day';
???
0000-12-31 00:00:00
(1 row)

names=>  select timestamp '0001-01-01' - interval '1 day';
?column?
0001-12-31 00:00:00 BC
(1 row)

If I try to go 1 year back than the previous query, I get an error in Octo.

OCTO> select timestamp '0001-01-01' - interval '1 day 1 year';
[ERROR]: ERR_INVALID_DATE_TIME_VALUE: "-001-12-31 00:00:00" is invalid for type "TIMESTAMP", format "TEXT" and datestyle "ISO, YMD"

Can we issue a similar error if the resulting year is 0000? That way we never go into this non-existent year territory.

Analysis

  • The range supported by Octo for date and timestamp are said to be following in doc/grammar.rst
Date                     : 0000-01-01 to 9999-12-31
Timestamp                : 0000-01-01 00:00:00.000000 to 9999-12-31 23:59:59.999999
Timestamp with time zone : 0000-01-01 00:00:00.000000-15:59:59 to 9999-12-31 23:59:59.999999+15:59:59

Date: -62167219200000000 (0000-01-01) to 253402214400000000 (9999-12-31)
Timestamp: -62167219200000000 (0000-01-01 00:00:00.000000) to 253402300799999999(9999-12-31 23:59:59.999999)
  • The range supported need to be adjusted such that 0000-01-01 results in an error in both zut and text format values
  • Following queries should result in an error after this change
select timestamp '0000-01-01';
select timestamp(zut)'-62167219200000000';

Change

  • IS_YEAR_VALID() and is_date_time_value_in_zut_range() in src/aux/ydboctodateoperations.c is where the validation of given date/time value happens. This is updated to consider 0001-01-01 as the allowed starting value of text and zut format date/time values.
  • The queries mentioned in Analysis section now issue an error and similar queries are tested by TDTT040 and TDTT066
  • The queries mentioned in the Issue section will be added to test by !1496

Doc

doc/grammar.rst is updated to have the new date/time range

Test

TDTT040 and TDTT066 is updated to validate the new change

Edited by Ganesh Mahesh

Merge request reports

Loading