You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "adwaitm1301 (via GitHub)" <gi...@apache.org> on 2026/07/31 12:51:08 UTC
[PR] fix(postgres): cast VARCHAR temporal columns to TIMESTAMP for DATE_TRUNC [superset]
adwaitm1301 opened a new pull request, #42639:
URL: https://github.com/apache/superset/pull/42639
### SUMMARY
Fixes #42386
When a string column on a physical dataset is manually marked as temporal, Superset passes it straight into `DATE_TRUNC`, which PostgreSQL rejects because `DATE_TRUNC` has no overload for `character varying`:
```
SELECT DATE_TRUNC('day', event_timestamp) AS event_timestamp, ...
```
This change makes `PostgresBaseEngineSpec.get_timestamp_expr` cast the column to `TIMESTAMP` before applying the grain when the underlying SQLAlchemy type is a string type. It builds on the existing override that handles pure `DATE` columns (see #42254), so both cases stay in one place.
Behavior that is intentionally left unchanged:
- `DATE` columns are still cast back to `DATE` after truncation, preserving the fix from #42254.
- `TIMESTAMP`/`DATETIME` columns are not cast.
- Epoch-based formats (`epoch_s`, `epoch_ms`) and bare years (`%Y`) keep their existing expressions.
- Columns without a grain, or without a known type, are not touched.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Not applicable.
### TESTING INSTRUCTIONS
1. Create a PostgreSQL table with a `VARCHAR` column holding timestamps, following the repro steps in #42386.
2. Create a physical dataset and mark the column as temporal.
3. Build a time series chart with a day grain and run it. The query now renders as:
```sql
SELECT DATE_TRUNC('day', CAST(event_timestamp AS TIMESTAMP)) AS event_timestamp, ...
```
4. Run the new unit tests:
```
pytest tests/unit_tests/db_engine_specs/test_postgres.py -k get_timestamp_expr
```
### ADDITIONAL INFORMATION
- [x] Has associated issue: #42386
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(postgres): cast VARCHAR temporal columns to TIMESTAMP for DATE_TRUNC [superset]
Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #42639:
URL: https://github.com/apache/superset/pull/42639#discussion_r3690839370
##########
superset/db_engine_specs/postgres.py:
##########
@@ -266,21 +266,39 @@ def get_timestamp_expr(
time_grain: str | None,
) -> TimestampExpression:
"""
- Construct a timestamp expression while preserving pure ``DATE`` semantics.
+ Construct a timestamp expression while preserving pure ``DATE`` semantics
+ and handling string columns marked as temporal.
Applying ``DATE_TRUNC`` to a ``DATE`` column implicitly casts the value to
``TIMESTAMP``, which can trigger unwanted timezone conversion on the client
and shift the displayed date by a day. To avoid this, the truncated value is
cast back to ``DATE`` when the source column is a pure ``DATE`` type.
See https://github.com/apache/superset/issues/42254.
+
+ ``DATE_TRUNC`` does not accept ``VARCHAR``/``TEXT`` arguments, so when a
+ string column is manually marked as temporal, its value is cast to
+ ``TIMESTAMP`` before the grain is applied. Otherwise the query fails with
+ ``function date_trunc(unknown, character varying) does not exist``.
+
+ See https://github.com/apache/superset/issues/42386.
"""
expr = super().get_timestamp_expr(col, pdf, time_grain)
col_type = getattr(col, "type", None)
# ``DateTime``/``TIMESTAMP`` are distinct SQLAlchemy types (not subclasses
# of ``Date``), so this only matches pure ``DATE`` columns.
if time_grain and isinstance(col_type, Date):
return TimestampExpression(f"CAST({expr.name} AS DATE)", col, type_=Date())
+ if (
+ time_grain
+ and pdf not in ("epoch_s", "epoch_ms", "%Y")
+ and isinstance(col_type, (String, Text))
+ ):
+ return TimestampExpression(
+ expr.name.replace("{col}", "CAST({col} AS TIMESTAMP)"),
+ col,
+ type_=DateTime(),
+ )
Review Comment:
**Suggestion:** The new branch applies a native PostgreSQL `CAST(... AS TIMESTAMP)` to every temporal string column regardless of `pdf`. Columns configured with formats such as `%d/%m/%Y` or other non-ISO layouts can contain values that PostgreSQL cannot parse with a plain cast, so queries that apply a grain still fail at runtime. Preserve format-aware parsing for custom date formats, or restrict this cast to formats that PostgreSQL accepts directly. [time/date]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Time-series charts fail for custom-formatted temporal strings.
- ❌ Grained temporal filters can fail during SQL execution.
- ⚠️ PostgreSQL receives format-unaware timestamp casts.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=9a8e5cb304fd433c86630bfd5ab07ad2&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=9a8e5cb304fd433c86630bfd5ab07ad2&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/db_engine_specs/postgres.py
**Line:** 292:301
**Comment:**
*Time Date: The new branch applies a native PostgreSQL `CAST(... AS TIMESTAMP)` to every temporal string column regardless of `pdf`. Columns configured with formats such as `%d/%m/%Y` or other non-ISO layouts can contain values that PostgreSQL cannot parse with a plain cast, so queries that apply a grain still fail at runtime. Preserve format-aware parsing for custom date formats, or restrict this cast to formats that PostgreSQL accepts directly.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42639&comment_hash=789489f1fbf052aff57dcd94679b1944d984fe6258a6c6addd124bca7d2509f4&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42639&comment_hash=789489f1fbf052aff57dcd94679b1944d984fe6258a6c6addd124bca7d2509f4&reaction=dislike'>👎</a>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(postgres): cast VARCHAR temporal columns to TIMESTAMP for DATE_TRUNC [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #42639:
URL: https://github.com/apache/superset/pull/42639#issuecomment-5143089660
<!-- Bito Reply -->
The flagged issue is correct. The current implementation only handles columns where `col.type` is explicitly a string type, but it fails for `literal_column()` objects used in SQL Lab or adhoc-column paths, which are often untyped even when metadata identifies them as temporal.
To resolve this, you should ensure that the `literal_column` is either propagated with the correct SQLAlchemy type or that the cast is applied using the temporal column metadata before `get_timestamp_expr` is called.
Since the current implementation is incomplete, I recommend updating the logic to check for the presence of temporal metadata on the column object itself, rather than relying solely on `col.type`.
**superset/db_engine_specs/postgres.py**
```
# ... existing logic ...
if (
time_grain
and pdf not in ("epoch_s", "epoch_ms", "%Y")
and (isinstance(col_type, (String, Text)) or getattr(col, "is_temporal", False))
):
return TimestampExpression(
expr.name.replace("{col}", "CAST({col} AS TIMESTAMP)"),
col,
type_=DateTime(),
)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(postgres): cast VARCHAR temporal columns to TIMESTAMP for DATE_TRUNC [superset]
Posted by "adwaitm1301 (via GitHub)" <gi...@apache.org>.
adwaitm1301 commented on PR #42639:
URL: https://github.com/apache/superset/pull/42639#issuecomment-5143163477
Thanks for the review, the flagged gap is real and I've fixed it.
After tracing all four `get_timestamp_expr` call sites, the untyped-column case only occurs in `Query.adhoc_column_to_sqla` in `superset/models/sql_lab.py`. The other callers already resolve the column type before reaching the engine spec:
- `TableColumn.get_timestamp_expression` (`superset/connectors/sqla/models.py`) builds the column with the type from `get_column_spec` (falling back to `DateTime`), so a VARCHAR column marked temporal arrives as `String`.
- `SqlaTable.adhoc_column_to_sqla` goes through `get_sqla_col`, which carries the same type, and its ad-hoc (non-metadata) branch only treats a column as temporal when the type probe says it is.
- `Dataset.get_timestamp_expression` (`superset/models/helpers.py`) does the same type resolution.
`Query.adhoc_column_to_sqla` was the exception: it built `literal_column(expression)` with no type even when `is_dttm` came from metadata, which is exactly why the `isinstance(col.type, (String, Text))` check missed it.
I went with your first suggested option rather than the `is_temporal` attribute. The attribute is not set on any SQLAlchemy expression today, so the check would be dead unless every caller starts setting it, and setting it broadly on temporal columns would wrap genuinely temporal columns in a no-op `CAST(... AS TIMESTAMP)` for Postgres. Propagating the resolved SQLAlchemy type from the result-column metadata puts the same information in the canonical place, so the existing engine-spec check handles it and no other engine is affected.
Changes in `9e51247`:
- `superset/models/sql_lab.py`: resolve the SQLAlchemy type from metadata and pass it to the `literal_column`.
- `tests/unit_tests/models/sql_lab_test.py`: regression test asserting the Postgres spec now renders `DATE_TRUNC('day', CAST(event_ts AS TIMESTAMP))` for a VARCHAR result column marked temporal.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(postgres): cast VARCHAR temporal columns to TIMESTAMP for DATE_TRUNC [superset]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #42639:
URL: https://github.com/apache/superset/pull/42639#issuecomment-5143341441
## [Codecov](https://app.codecov.io/gh/apache/superset/pull/42639?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `16.66667%` with `5 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 55.88%. Comparing base ([`7d2b184`](https://app.codecov.io/gh/apache/superset/commit/7d2b184079811d07fd3f525f1b3592987095474a?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`9e51247`](https://app.codecov.io/gh/apache/superset/commit/9e512477b8cc2d3d229d01dd93ebb1e8c9227a5c?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
| [Files with missing lines](https://app.codecov.io/gh/apache/superset/pull/42639?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [superset/models/sql\_lab.py](https://app.codecov.io/gh/apache/superset/pull/42639?src=pr&el=tree&filepath=superset%2Fmodels%2Fsql_lab.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbW9kZWxzL3NxbF9sYWIucHk=) | 0.00% | [3 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/42639?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [superset/db\_engine\_specs/postgres.py](https://app.codecov.io/gh/apache/superset/pull/42639?src=pr&el=tree&filepath=superset%2Fdb_engine_specs%2Fpostgres.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvZGJfZW5naW5lX3NwZWNzL3Bvc3RncmVzLnB5) | 33.33% | [2 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/42639?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
> :exclamation: There is a different number of reports uploaded between BASE (7d2b184) and HEAD (9e51247). Click for more details.
>
> <details><summary>HEAD has 4 uploads less than BASE</summary>
>
>| Flag | BASE (7d2b184) | HEAD (9e51247) |
>|------|------|------|
>|python|6|2|
></details>
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #42639 +/- ##
==========================================
- Coverage 65.44% 55.88% -9.57%
==========================================
Files 2810 2810
Lines 159362 159366 +4
Branches 36372 36373 +1
==========================================
- Hits 104295 89055 -15240
- Misses 53025 69479 +16454
+ Partials 2042 832 -1210
```
| [Flag](https://app.codecov.io/gh/apache/superset/pull/42639/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [hive](https://app.codecov.io/gh/apache/superset/pull/42639/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `38.08% <16.66%> (-0.01%)` | :arrow_down: |
| [mysql](https://app.codecov.io/gh/apache/superset/pull/42639/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [postgres](https://app.codecov.io/gh/apache/superset/pull/42639/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [presto](https://app.codecov.io/gh/apache/superset/pull/42639/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `39.98% <16.66%> (-0.01%)` | :arrow_down: |
| [python](https://app.codecov.io/gh/apache/superset/pull/42639/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `40.03% <16.66%> (-19.23%)` | :arrow_down: |
| [sqlite](https://app.codecov.io/gh/apache/superset/pull/42639/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [unit](https://app.codecov.io/gh/apache/superset/pull/42639/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/superset/pull/42639?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(postgres): cast VARCHAR temporal columns to TIMESTAMP for DATE_TRUNC [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #42639:
URL: https://github.com/apache/superset/pull/42639#issuecomment-5144946748
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers a full AI review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(postgres): cast VARCHAR temporal columns to TIMESTAMP for DATE_TRUNC [superset]
Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #42639:
URL: https://github.com/apache/superset/pull/42639#discussion_r3690559439
##########
superset/db_engine_specs/postgres.py:
##########
@@ -266,21 +266,39 @@ def get_timestamp_expr(
time_grain: str | None,
) -> TimestampExpression:
"""
- Construct a timestamp expression while preserving pure ``DATE`` semantics.
+ Construct a timestamp expression while preserving pure ``DATE`` semantics
+ and handling string columns marked as temporal.
Applying ``DATE_TRUNC`` to a ``DATE`` column implicitly casts the value to
``TIMESTAMP``, which can trigger unwanted timezone conversion on the client
and shift the displayed date by a day. To avoid this, the truncated value is
cast back to ``DATE`` when the source column is a pure ``DATE`` type.
See https://github.com/apache/superset/issues/42254.
+
+ ``DATE_TRUNC`` does not accept ``VARCHAR``/``TEXT`` arguments, so when a
+ string column is manually marked as temporal, its value is cast to
+ ``TIMESTAMP`` before the grain is applied. Otherwise the query fails with
+ ``function date_trunc(unknown, character varying) does not exist``.
+
+ See https://github.com/apache/superset/issues/42386.
"""
expr = super().get_timestamp_expr(col, pdf, time_grain)
col_type = getattr(col, "type", None)
# ``DateTime``/``TIMESTAMP`` are distinct SQLAlchemy types (not subclasses
# of ``Date``), so this only matches pure ``DATE`` columns.
if time_grain and isinstance(col_type, Date):
return TimestampExpression(f"CAST({expr.name} AS DATE)", col, type_=Date())
+ if (
+ time_grain
+ and pdf not in ("epoch_s", "epoch_ms", "%Y")
+ and isinstance(col_type, (String, Text))
Review Comment:
**Suggestion:** The cast is gated on `col.type` being a string type, but SQL Lab and adhoc-column paths construct temporal expressions with untyped `literal_column()` objects even after metadata identifies them as temporal. Those callers therefore still generate `DATE_TRUNC(..., raw_string_expression)` and PostgreSQL raises the same overload error. Propagate the discovered SQLAlchemy type to the literal column or apply the cast using the temporal column metadata before calling this method. [incomplete implementation]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ SQL Lab adhoc time-series queries can still fail.
- ❌ Adhoc chart columns may retain invalid DATE_TRUNC SQL.
- ⚠️ Physical-column paths remain fixed when metadata supplies types.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=2eb2998d10914cf098d7107229e896bd&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=2eb2998d10914cf098d7107229e896bd&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/db_engine_specs/postgres.py
**Line:** 295:295
**Comment:**
*Incomplete Implementation: The cast is gated on `col.type` being a string type, but SQL Lab and adhoc-column paths construct temporal expressions with untyped `literal_column()` objects even after metadata identifies them as temporal. Those callers therefore still generate `DATE_TRUNC(..., raw_string_expression)` and PostgreSQL raises the same overload error. Propagate the discovered SQLAlchemy type to the literal column or apply the cast using the temporal column metadata before calling this method.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42639&comment_hash=479572f19338a197b904f9d2b2b8f5fcd7e4c4b69547f5787535df2401ef35ed&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42639&comment_hash=479572f19338a197b904f9d2b2b8f5fcd7e4c4b69547f5787535df2401ef35ed&reaction=dislike'>👎</a>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(postgres): cast VARCHAR temporal columns to TIMESTAMP for DATE_TRUNC [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #42639:
URL: https://github.com/apache/superset/pull/42639#issuecomment-5143044523
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org