Documentation Index
Fetch the complete documentation index at: https://private-7c7dfe99-page-updates.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Data Types
Type conversions
The client aims to be as flexible as possible concerning accepting variable types for both insertion and marshaling of responses. In most cases, an equivalent Golang type exists for a ClickHouse column type, e.g., UInt64 to uint64. These logical mappings should always be supported. You may wish to utilize variable types that can be inserted into columns or used to receive a response if the conversion of either the variable or received data takes place first. The client aims to support these conversions transparently, so users don’t need to convert their data to align precisely before insertion and to provide flexible marshaling at query time. This transparent conversion doesn’t allow for precision loss. For example, a uint32 can’t be used to receive data from a UInt64 column. Conversely, a string can be inserted into a datetime64 field provided it meets the format requirements. The type conversions currently supported for primitive types are captured here. This effort is ongoing and can be separated into insertion (Append/AppendRow) and read time (via a Scan). Should you need support for a specific conversion, please raise an issue.
The standard database/sql interface should support the same types as the ClickHouse API. There are a few exceptions, primarily for complex types, that are documented in the sections below. Similar to the ClickHouse API, the client aims to be as flexible as possible concerning accepting variable types for both insertion and marshaling of responses.
Complex types
Date/DateTime
The ClickHouse go client supports theDate, Date32, DateTime, and DateTime64 date/datetime types. Dates can be inserted as a string in the format 2006-01-02 or using the native go time.Time{} or sql.NullTime. DateTimes also support the latter types but require strings to be passed in the format 2006-01-02 15:04:05 with an optional timezone offset e.g. 2006-01-02 15:04:05 +08:00. time.Time{} and sql.NullTime are both supported at read time as well as any implementation of of the sql.Scanner interface.
Handling of timezone information depends on the ClickHouse type and whether the value is being inserted or read:
- DateTime/DateTime64
- At insert time the value is sent to ClickHouse in UNIX timestamp format. If no time zone is provided, the client will assume the client’s local time zone.
time.Time{}orsql.NullTimewill be converted to epoch accordingly. - At select time the timezone of the column will be used if set when returning a
time.Timevalue. If not, the timezone of the server will be used.
- At insert time the value is sent to ClickHouse in UNIX timestamp format. If no time zone is provided, the client will assume the client’s local time zone.
- Date/Date32
- At insert time, the timezone of any date is considered when converting the date to a unix timestamp, i.e., it will be offset by the timezone prior to storage as a date, as Date types have no locale in ClickHouse. If this isn’t specified in a string value, the local timezone will be used.
- At select time, dates are scanned into
time.Time{}orsql.NullTime{}instances will be returned without timezone information.
Time/Time64 types
TheTime and Time64 column types store time-of-day values without a date component. Both are mapped to Go’s time.Duration.
Timestores the time with second precision.Time64(precision)supports sub-second precision (likeDateTime64), where precision is 0–9.
Array
Arrays should be inserted as slices. Typing rules for the elements are consistent with those for the primitive type, i.e., where possible elements will be converted. A pointer to a slice should be provided at Scan time.Map
Maps should be inserted as Golang maps with keys and values conforming to the type rules defined earlier.When using the database/sql API, Map values require strict typing - you cannot use
interface{} as the value type. For example, you cannot pass a map[string]interface{} for a Map(String,String) field and must use a map[string]string instead. An interface{} variable will always be compatible and can be used for more complex structures.Full ExampleTuples
Tuples represent a group of Columns of arbitrary length. The columns can either be explicitly named or only specify a type e.g.Nested
A Nested field is equivalent to an Array of named Tuples. Usage depends on whether the user has set flatten_nested to 1 or 0. By setting flatten_nested to 0, Nested columns stay as a single array of tuples. This allows you to use slices of maps for insertion and retrieval and arbitrary levels of nesting. The map’s key must equal the column’s name, as shown in the example below. Note: since the maps represent a tuple, they must be of the typemap[string]interface{}. The values are currently not strongly typed.
flatten_tested=0
If the default value of 1 is used for flatten_nested, nested columns are flattened to separate arrays. This requires using nested slices for insertion and retrieval. While arbitrary levels of nesting may work, this isn’t officially supported.
flatten_nested=1
Note: Nested columns must have the same dimensions. For example, in the above example, Col_2_2 and Col_2_1 must have the same number of elements.
Due to a more straightforward interface and official support for nesting, we recommend flatten_nested=0.
Geo types
The client supports the geo types Point, Ring, LineString, Polygon, MultiPolygon, and MultiLineString. These types are represented in Go using the github.com/paulmach/orb package.UUID
The UUID type is supported by the github.com/google/uuid package. You can also send and marshal a UUID as a string or any type which implementssql.Scanner or Stringify.
Decimal
Due to Go’s lack of a built-in Decimal type, we recommend using the third-party package github.com/shopspring/decimal to work with Decimal types natively without modifying your original queries.You may be tempted to use Float instead to avoid third-party dependencies. However, be aware that Float types in ClickHouse aren’t recommended when accurate values are required.If you still choose to use Go’s built-in Float type on the client side, you must explicitly convert Decimal to Float using the toFloat64() function or its variants in your ClickHouse queries. Be aware that this conversion may result in loss of precision.
Nullable
The go value of Nil represents a ClickHouse NULL. This can be used if a field is declared Nullable. At insert time, Nil can be passed for both the normal and Nullable version of a column. For the former, the default value for the type will be persisted, e.g., an empty string for string. For the nullable version, a NULL value will be stored in ClickHouse. At scan time, the user must pass a pointer to a type that supports nil, e.g., *string, in order to represent the nil value for a Nullable field. In the example below, col1, which is a Nullable(String), thus receives a **string. This allows nil to be represented.sql.Null* types e.g. sql.NullInt64. These are compatible with their equivalent ClickHouse types.
Big Ints
Number types larger than 64 bits are represented using the native go big package.BFloat16
BFloat16 is a 16-bit brain float type used in machine learning workloads. In Go, BFloat16 values are inserted and scanned as float32. Nullable variants use sql.NullFloat64.
QBit
QBit is an experimental column type for storing vector embeddings in bit-sliced format, optimized for vector similarity search. It requires the allow_experimental_qbit_type setting to be enabled.
In Go, a QBit(Float32, N) column is inserted and scanned as []float32 where N is the vector dimension.
