-
Notifications
You must be signed in to change notification settings - Fork 95
Open
Labels
Description
Describe the bug
ClickHouse ODBC driver do not support SQL_TSI_FRAC_SECOND
which could leads to some queries failing in PowerBI when using a date table (https://learn.microsoft.com/en-us/power-bi/guidance/model-date-tables, https://www.datacamp.com/tutorial/how-to-create-date-tables-in-power-bi-tutorial)
For example:
SELECT Date, floor(CAST(dateDiff('day', _CAST(0, 'Nullable(Date)'), addDays(Date, _CAST(2, 'Nullable(Int32)'))), 'Float64') + ((CAST(dateDiff(SQL_TSI_FRAC_SECOND, addDays(_CAST(0, 'Nullable(Date)'), dateDiff('day', _CAST(2, 'Nullable(Int32)'), addDays(Date, _CAST(0, 'Nullable(Date)')))), addDays(Date, _CAST(2, 'Nullable(Int32)'))), 'Float64') / _CAST(86400000., 'Nullable(Float64)')) * multiIf(addDays(Date, _CAST(2, 'Nullable(Int32)')) < _CAST('-2208988800', 'Nullable(DateTime64(9))'), _CAST(-1, 'Nullable(Int32)'), _CAST(1, 'Nullable(Int32)')))) AS C1 FROM db.Date WHERE NOT (Date IS NULL).
Clickhouse dateDiff
does support nanoseconds (https://clickhouse.com/docs/sql-reference/functions/date-time-functions#date_diff) and so support could be added to the driver.
SQL_TSI_FRAC_SECOND
match with nanoseconds as units: https://calcite.apache.org/javadocAggregate/org/apache/calcite/sql/fun/SqlTimestampAddFunction.html
Expected behaviour
date_diff at the nanoseconds level should succeed
Error log
Unknown expression or function identifier 'SQL_TSI_FRAC_SECOND'
Query log
Configuration
Environment
- Driver version: 1.4.1.20250523
- OS: Windows Server 2022 Datacenter 21H2
- ODBC Driver manager:
ClickHouse server
- ClickHouse Server version: 24.8
CREATE TABLE
statements for tables involved:- Sample data for all these tables, use clickhouse-obfuscator if necessary
custom date table schema:
-- db.`Date` definition
CREATE TABLE db.Date
(
`PK_ID` String,
`PK_ID_Number` Int32,
`Date` DateTime,
`Year` LowCardinality(String),
`Month` LowCardinality(String),
`Month_Number` Int32,
`Month_Year` LowCardinality(String)
)
ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/db/Date/{uuid}',
'{replica}')
PRIMARY KEY PK_ID
ORDER BY PK_ID
SETTINGS index_granularity = 8192;