Skip to content

Time64 ScanType and ScanRow mismatch #1757

@jgao54

Description

@jgao54

Observed

While working on adding TIME64 support for CDC pipes, we run the following logic to query a table:

rows, rowsErr = ch.Query("select <col1>, <col2>, <col3>, ... from <table>")
row := make([]any, 0, numColumns)
for _, ty:= range colTypes {
    row = append(row, reflect.New(ty.ScanType()).Interface())
}
for rows.Next() {
    if err := rows.Scan(row...); err != nil {
        ...
    }
}

this is failing with: clickhouse [ScanRow]: (t) converting Time64 to *time.Time is unsupported

I then tried the workaround by scanning it into *time.Duration.

typeName := ty.DatabaseTypeName()
if dbTypeName == "Time64(6)" {
    row = append(row, new(time.Duration))
}

It successfully scanned this time, however the precision is in millisecond instead of the expected microseconds. Not sure if this is a bug or if it's an issue in how it's used.

Expected behaviour

  • ScanType() should match ScanRow()
  • no loss in precision during scan

Code example

see above

Error log

 clickhouse [ScanRow]: (t) converting Time64 to *time.Time is unsupported

Details

Environment

  • clickhouse-go version: 2.42.0
  • Interface: ClickHouse API / database/sql compatible driver
  • Go version: 1.25.5
  • Operating system: Linux
  • ClickHouse version: 25.11.2
  • Is it a ClickHouse Cloud? no
  • ClickHouse Server non-default settings, if any:
  • CREATE TABLE statements for tables involved:
  • Sample data for all these tables, use clickhouse-obfuscator if necessary

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions