Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1970-01-01's datatime64 scan Error #1222

Closed
BoolWang opened this issue Mar 6, 2024 · 2 comments
Closed

1970-01-01's datatime64 scan Error #1222

BoolWang opened this issue Mar 6, 2024 · 2 comments
Labels

Comments

@BoolWang
Copy link

BoolWang commented Mar 6, 2024

When the v2 version of the ClickHouse driver reads a datetime64 type and it corresponds to the UTC time 1970-01-01 00:00:00, it will be incorrectly read as the time.Time 0001-01-01T00:00:00Z.

Steps to reproduce

  1. Create the table data_type_test with the field c_datatime64_utc as datetime64(8,'UTC'), and insert the data 1970-01-01T00:00:00.
  2. When using the v2 driver to retrieve the data, it is found that the conversion is incorrect.

Code example

func TestDateAndDateTime(t *testing.T) {
	connect := chv2.OpenDB(&chv2.Options{
		Addr: []string{fmt.Sprintf("%s:%s", host, port)},
		Auth: chv2.Auth{
			Database: dbname,
			Username: user,
			Password: password,
		},
	})
	defer connect.Close()

	rows, err := connect.Query("select c_datetime64_utc from data_type_test")
	if err != nil {
		t.Fatal(err)
	}
	defer rows.Close()

	colType, _ := rows.ColumnTypes()
	fmt.Println(colType[0].DatabaseTypeName())
	for rows.Next() {
		var arrayStringField []byte
		if err := rows.Scan(&arrayStringField); err != nil {
			t.Fatal(err)
		}

		fmt.Println(string(arrayStringField))
	}
}
@BoolWang BoolWang added the bug label Mar 6, 2024
@BoolWang
Copy link
Author

BoolWang commented Mar 6, 2024

The same situation also occurs with datetime types.

@jkaflik
Copy link
Contributor

jkaflik commented Mar 28, 2024

Fixed in #1228

@jkaflik jkaflik closed this as completed Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants