clickhouse-java icon indicating copy to clipboard operation
clickhouse-java copied to clipboard

Problem with Array(DateTime) in PreparedStatement

Open TanVD opened this issue 8 years ago • 3 comments

In current implementation "Timestamp.toString()" is used in setValue for arrays. It leads to inability to insert Array(DateTime). And this code will not work: statement.setArray(index, statement.connection.createArrayOf("Array(DateTime)", array)) with following exception (with example DateTime) String is too long for DateTime: 2001-01-01 11:11:11.0

TanVD avatar Nov 02 '17 13:11 TanVD

Thanks for report. In fact arrays are currently serialized different from single values of corresponding types set with setObject. For example timezones are not considered for Date and Timestamp in arrays.

serebrserg avatar Nov 02 '17 17:11 serebrserg

Is it the same issue?

Timestamp[] arr = {...}; statement.setArray(2, new ClickHouseArray(type, arr));

throws an exception:

DB::Exception: Cannot parse input: expected \' before: .358\',\'2019-04-03 16:52:43.358\']\n2019-04-03 13:52:43\t[\'2019-04-03 15:52:43.358\',\'2019-04-03 16:52:43.358\']\n: (at row 1)

Blackmorse avatar Apr 03 '19 12:04 Blackmorse

Looks like

TanVD avatar May 07 '19 12:05 TanVD

The driver has transitioned to the RowBinary data format starting from v0.3.2. It's now recommended to utilize input functions and appropriate objects for insertion, such as LocalDateTime[] in this instance.

zhicwu avatar May 18 '23 23:05 zhicwu