diff --git a/src/Octonica.ClickHouseClient/ClickHouseCommand.cs b/src/Octonica.ClickHouseClient/ClickHouseCommand.cs index 4bef407..2f78db3 100644 --- a/src/Octonica.ClickHouseClient/ClickHouseCommand.cs +++ b/src/Octonica.ClickHouseClient/ClickHouseCommand.cs @@ -903,7 +903,11 @@ private string PrepareCommandText(IClickHouseTypeInfoProvider typeInfoProvider, if (typeSeparatorIdx >= 0) queryStringBuilder.Append("(CAST("); - queryStringBuilder.Append("(SELECT ").Append(parametersTable).Append('.').Append(parameter.Id).Append(" FROM ").Append(parametersTable).Append(')'); + queryStringBuilder.Append("(SELECT ") + .Append(parameter.IsArray ? "arrayJoin(" : "") + .Append(parametersTable).Append('.') + .Append(parameter.Id) + .Append(parameter.IsArray ? ")" : "").Append(" FROM ").Append(parametersTable).Append(')'); if (typeSeparatorIdx >= 0) queryStringBuilder.Append(" AS ").Append(query, offset + typeSeparatorIdx + 1, length - typeSeparatorIdx - 2).Append("))"); diff --git a/src/Octonica.ClickHouseClient/Types/DateTime64TypeInfo.cs b/src/Octonica.ClickHouseClient/Types/DateTime64TypeInfo.cs index 3c9c17c..6832fce 100644 --- a/src/Octonica.ClickHouseClient/Types/DateTime64TypeInfo.cs +++ b/src/Octonica.ClickHouseClient/Types/DateTime64TypeInfo.cs @@ -350,7 +350,7 @@ protected override ulong Convert(DateTime value) } } - private sealed class DateTimeOffsetWriter : StructureWriterBase + private sealed class DateTimeOffsetWriter : StructureWriterBase { private readonly int _ticksScale; private readonly long _ticksMaxValue; @@ -364,9 +364,9 @@ public DateTimeOffsetWriter(string columnName, string columnType, int precision, _timeZone = timeZone; } - protected override ulong Convert(DateTimeOffset value) + protected override long Convert(DateTimeOffset value) { - ulong ticks; + long ticks; if (value == default) { ticks = 0; @@ -376,13 +376,11 @@ protected override ulong Convert(DateTimeOffset value) var offset = _timeZone.GetUtcOffset(value); var valueWithOffset = value.ToOffset(offset); var dateTimeTicks = (valueWithOffset - DateTimeOffset.UnixEpoch).Ticks; - if (dateTimeTicks < 0 || dateTimeTicks > _ticksMaxValue) - throw new OverflowException($"The value must be in range [{DateTimeOffset.UnixEpoch:O}, {DateTimeOffset.UnixEpoch.AddTicks(_ticksMaxValue):O}]."); if (_ticksScale < 0) - ticks = checked((ulong) dateTimeTicks * (uint) -_ticksScale); + ticks = checked(dateTimeTicks * (uint) -_ticksScale); else - ticks = (ulong) dateTimeTicks / (uint) _ticksScale; + ticks = dateTimeTicks / (uint) _ticksScale; } return ticks;