Query with date field filter using cast date and `BETWEEN` in the `WHERE` clause
- Dominant language
- Rust
- Stars
- 20.8k
- Forks
- 2.1k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 181
Description
**Failed SQL**
Search for `Failed SQL` log message:
```
data-product-cube-1 | Cube SQL Error: undefined
data-product-cube-1 | --
data-product-cube-1 | "SELECT * FROM sessions_count_view WHERE CAST(\"public\".\"sessions_count_view\".\"start_scheduled_at\" AS DATE) BETWEEN DATE '2023-05-01' AND DATE '2023-07-31'"
data-product-cube-1 | --
data-product-cube-1 | {
data-product-cube-1 | "apiType": "sql",
data-product-cube-1 | "appName": "NULL",
data-product-cube-1 | "sanitizedQuery": "SELECT * FROM sessions_count_view WHERE CAST(\"public\".\"sessions_count_view\".\"start_scheduled_at\" AS DATE) BETWEEN DATE '2023-05-01' AND DATE '2023-07-31'",
data-product-cube-1 | "protocol": "postgres"
data-product-cube-1 | }
data-product-cube-1 | Error during rewrite: Can't detect Cube query and it may be not supported yet. Please check logs for additional information.
```
**Logical Plan**
Search for `Can't rewrite plan` log message:
```
Error during rewrite: Can't detect Cube query and it may be not supported yet. Please check logs for additional information.
```
**Version:**
v0.33.42
**Additional context**
I am using Metabase's SQL native question with a field filter of date type. Metabase generates the following query to run on cube.dev's PostgreSQL database:
```sql
SELECT * FROM sessions_count_view WHERE CAST("public"."sessions_count_view"."start_scheduled_at" AS date) BETWEEN date '2023-05-01' AND date '2023-07-31';
```
However, when attempting to execute this query, I encounter the following error in the logs:
```
Cube SQL Error: undefined
"SELECT * FROM sessions_count_view WHERE CAST(\"public\".\"sessions_count_view\".\"start_scheduled_at\" AS DATE) BETWEEN DATE '2023-05-01' AND DATE '2023-07-31'"
{
"apiType": "sql",
"appName": "NULL",
"sanitizedQuery": "SELECT * FROM sessions_count_view WHERE CAST(\"public\".\"sessions_count_view\".\"start_scheduled_at\" AS DATE) BETWEEN DATE '2023-05-01' AND DATE '2023-07-31'",
"protocol": "postgres"
}
Error during rewrite: Can't detect Cube query and it may be not supported yet. Please check logs for additional information.
```
It seems that the query generated by Metabase is encountering an issue when executing on cube.dev, resulting in the inability to detect the Cube query and possibly lacking support for the specified operation. This could be related to the usage of `CAST` and the `BETWEEN` clause in the query. I would appreciate assistance in resolving this issue or any insights into potential workarounds. Thank you!
Contributor guide
Assessment
This issue has not been assessed yet.