ClickHouse C# Client
The official C# client for connecting to ClickHouse. The client source code is available in the GitHub repository. Originally developed by Oleg V. Kozlyuk.
Migration guide
- Update
.csprojwithClickHouse.Drivername and the latest version of the package. - Update your code to use the new
ClickHouse.Drivernamespace and classes.
Supported .NET Versions
ClickHouse.Driver supports the following .NET versions:
- .NET Framework 4.6.2
- .NET Framework 4.8
- .NET Standard 2.1
- .NET 6.0
- .NET 8.0
- .NET 9.0
Installation
Install the package from NuGet:
Or using the NuGet Package Manager:
Usage
Creating a Connection
Create a connection using a connection string:
Creating a Table
Create a table using standard SQL syntax:
Inserting Data
Insert data using parameterized queries:
Bulk Insert
Performing SELECT Queries
Execute SELECT queries and process results:
Raw streaming
Supported Data Types
ClickHouse.Driver supports the following ClickHouse data types:
Boolean Type
Bool(bool)
Numeric Types:
Int8(sbyte)Int16(short)Int32(int)Int64(long)Int128(BigInteger)Int256(BigInteger)UInt8(byte)UInt16(ushort)UInt32(uint)UInt64(ulong)UInt128(BigInteger)UInt256(BigInteger)Float32(float)Float64(double)Decimal(decimal)Decimal32(decimal)Decimal64(decimal)Decimal256(BigDecimal)
String Types
String(string)FixedString(string)
Date and Time Types
Date(DateTime)Date32(DateTime)DateTime(DateTime)DateTime32(DateTime)DateTime64(DateTime)
Network Types
IPv4(IPAddress)IPv6(IPAddress)
Geo Types
Point(Tuple)Ring(Array of Points)Polygon(Array of Rings)
Complex Types
Array(Array of any type)Tuple(Tuple of any types)Nullable(Nullable version of any type)
DateTime handling
ClickHouse.Driver tries to correctly handle timezones and DateTime.Kind property. Specifically:
DateTime values are returned as UTC. User can then convert them themselves or use ToLocalTime() method on DateTime instance.
When inserting, DateTime values are handled in following way:
- UTC
DateTimeare inserted as is, because ClickHouse stores them in UTC internally - Local
DateTimeare converted to UTC according to user's local timezone settings - Unspecified
DateTimeare considered to be in target column's timezone, and hence are converted to UTC according to that timezone