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

IllegalArgumentException caused by local default datetime when using nullAsDefault property

Open yanye666 opened this issue 1 year ago • 4 comments

Still got this problem in version:0.3.2-patch11, When I set 0 or null timestamp to ClickHouse DataTime column,I got this err

DateTime(-28800) should between 0 and 4294967295000 inclusive of both values

Originally posted by @cod-soap in https://github.com/ClickHouse/clickhouse-java/issues/999#issuecomment-1445802811

yanye666 avatar Jul 16 '24 09:07 yanye666

When I set the object property string to "1970-01-01 00:00:00" ,throw exception,below the debug

image

When I set the object property string to "1970-01-01 08:00:00" ,avoid exception,database query show image

yanye666 avatar Jul 16 '24 09:07 yanye666

Good day, @yanye666 !

How do you set null timestamp?

Here is my code that works for latest version 0.6.2

 try (ClickHouseConnection conn = newConnection(props);
                PreparedStatement ps = conn.prepareStatement("select toDateTime(?)")) {

            ps.setTimestamp(1, null);
            ResultSet rs = ps.executeQuery();
            Assert.assertTrue(rs.next());
            Assert.assertNull(rs.getObject(1));
        }

Thanks!

chernser avatar Jul 16 '24 21:07 chernser

Good day, @yanye666 !

How do you set null timestamp?

Here is my code that works for latest version 0.6.2


 try (ClickHouseConnection conn = newConnection(props);

                PreparedStatement ps = conn.prepareStatement("select toDateTime(?)")) {



            ps.setTimestamp(1, null);

            ResultSet rs = ps.executeQuery();

            Assert.assertTrue(rs.next());

            Assert.assertNull(rs.getObject(1));

        }

Thanks!

I'm not set null.I want to insert the default 1970 timestamp to avoid clickhouse nullable. But as shown in the figure, I have to set 1970-01-01 08:00:00, otherwise I will report an error.Inspection of the first diagram

yanye666 avatar Jul 17 '24 00:07 yanye666

@yanye666 this is the problem with timezone and Dates. This check is valid because it prevents writing dates before 1970-01-01 00:00:00. But as you are in Tz +8 it means that passed date is ahead of UTC by 8h and when it is converted into UTC it will be before 1970-01-01 00:00:00.

chernser avatar Jan 27 '25 17:01 chernser