ClickHouseClient icon indicating copy to clipboard operation
ClickHouseClient copied to clipboard

Date/Date32/DateTime/DateTime64 min value read as 0001-01-01

Open MaceWindu opened this issue 3 years ago • 5 comments

CREATE TABLE IF NOT EXISTS TypeTable
(
	Id             Int32  NOT NULL,
	Column         Date32 NOT NULL,
)
ENGINE = Memory()

INSERT INTO TypeTable
(
	Id,
	Column
)
VALUES
(toInt32(1),toDate32('1925-01-01'))

Data reader's GetValue/GetDate method returns default value 0001-01-01 instead of actual value from table. Works fine for max-value (2283-11-11) or 1925-01-02.

MaceWindu avatar Jun 27 '22 19:06 MaceWindu

Actually, same issue for Date and 1970-01-01 value

MaceWindu avatar Jun 27 '22 20:06 MaceWindu

DateTime affected too. Not tested DateTime64 yet, but probably also affected.

MaceWindu avatar Jun 27 '22 21:06 MaceWindu

DateTime64 also returns 0001-01-01 for 1970-01-01 Values prior to this date result in exception #62

MaceWindu avatar Jul 02 '22 17:07 MaceWindu

I don't get DateTime.MinValue value while fetching DateTime64 fields with value less than 1970-01-01, but I get exception:

Octonica.ClickHouseClient.Exceptions.ClickHouseHandledException
The value must be in range [1970-01-01T00:00:00.0000000+00:00, 9999-12-31T23:59:59.9999999+00:00].
CREATE TABLE IF NOT EXISTS TypeTable
(
    Id            Int32,
    Column  DateTime64
)
    ENGINE = Memory();

INSERT INTO TypeTable (Id, Column) VALUES (1, toDateTime64('1925-01-01', 3));

Fetching code:

public class TypeTable
{
    int            Id     { get; set; }
    DateTimeOffset Column { get; set; }
}

var result = await _connection.QueryFirstOrDefaultAsync<TypeTable>("SELECT * FROM TypeTable");

Alex69rus avatar Jul 07 '22 08:07 Alex69rus

Also there is a problem with filtering by DateTime64 values:

var result = await _connection.QueryFirstOrDefaultAsync<TypeTable>(
    new CommandDefinition(
      "SELECT * FROM TypeTable WHERE Column > {DateTimeFilter:DateTime64}",
      new Dictionary<string, object>
      {
          { "DateTimeFilter", new DateTimeOffset(1930, 1, 1, 1, 1, 1, TimeSpan.Zero) }
      }
  )
);

Exception:

Octonica.ClickHouseClient.Exceptions.ClickHouseHandledException
The value must be in range [1970-01-01 00:00:00, 2105-12-31 23:59:59].

Alex69rus avatar Jul 07 '22 08:07 Alex69rus