MallikarjunaReddyN opened a new issue, #42386:
URL: https://github.com/apache/superset/issues/42386

   ### Bug description
   
   When using a Physical Dataset in Apache Superset, users can mark a VARCHAR 
column as Temporal from the dataset column configuration.
   
   Superset saves this metadata successfully, but when creating a Time-series 
chart using that column, Superset generates a DATE_TRUNC() expression directly 
on the VARCHAR column.
   
   For PostgreSQL databases, this results in a query execution failure because 
DATE_TRUNC() does not support VARCHAR arguments.
   
   Steps to reporduce:
   
   1. Create a PostgreSQL table
   ```
   CREATE TABLE website_events (
       id SERIAL PRIMARY KEY,
       event_name VARCHAR(50),
       user_count INTEGER,
       event_timestamp VARCHAR(30)
   );
   ```
   2. Insert sample data
   ```
   INSERT INTO website_events 
   (event_name, user_count, event_timestamp)
   VALUES
   ('Page View', 120, '2026-07-01 08:00:00'),
   ('Login', 80, '2026-07-01 09:00:00'),
   ('Purchase', 40, '2026-07-01 10:00:00'),
   ('Logout', 60, '2026-07-01 11:00:00'),
   
   ('Page View', 200, '2026-07-02 08:00:00'),
   ('Login', 100, '2026-07-02 09:00:00'),
   ('Purchase', 55, '2026-07-02 10:00:00'),
   ('Logout', 70, '2026-07-02 11:00:00');
   ```
   3. Create a Physical Dataset
   4. Edit dataset columns
   `Dataset → Edit Dataset → Columns` Change: event_timestamp to `Is temporal = 
True`
   5. Create a Time-series chart
   ```
   Time Column:
   event_timestamp
   
   Time Grain:
   Day
   
   Metric:
   SUM(user_count)
   ```
   
   **Actual behavior:**
   Superset generates SQL similar to:
   ```
   SELECT
       DATE_TRUNC('day', event_timestamp) AS event_timestamp,
       SUM(user_count) AS sum__user_count
   FROM website_events
   GROUP BY DATE_TRUNC('day', event_timestamp)
   ORDER BY event_timestamp;
   ```
   PostgreSQL returns:
   ```
   psycopg2.errors.UndefinedFunction:
   function date_trunc(unknown, character varying) does not exist
   
   LINE 1:
   SELECT DATE_TRUNC('day', event_timestamp)
                            ^
   
   HINT:
   No function matches the given name and argument types.
   You might need to add explicit type casts.
   ```
   
   ### Screenshots/recordings
   
   
https://github.com/user-attachments/assets/ffb06c99-82c8-48dc-bc4e-57c0baab6042
   
   ### Superset version
   
   master / latest-dev
   
   ### Python version
   
   3.11
   
   ### Node version
   
   18 or greater
   
   ### Browser
   
   Chrome
   
   ### Additional context
   
   Superset backend logs:
   2026-07-24 13:43:59,495:WARNING:superset.models.helpers:Query SELECT 
DATE_TRUNC('day', event_timestamp) AS event_timestamp, sum(user_count) AS 
"SUM(user_count)" 
   FROM public.website_events GROUP BY DATE_TRUNC('day', event_timestamp) ORDER 
BY "SUM(user_count)" DESC 
    LIMIT 10000 on schema public failed
   Traceback (most recent call last):
     File "/home/superset/Personal/superset/superset/models/helpers.py", line 
1668, in query
       df = self.database.get_df(
            ^^^^^^^^^^^^^^^^^^^^^
     File "/home/superset/Personal/superset/superset/models/core.py", line 909, 
in get_df
       cursor, rows, description = self._execute_sql_with_mutation_and_logging(
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File "/home/superset/Personal/superset/superset/models/core.py", line 861, 
in _execute_sql_with_mutation_and_logging
       self.db_engine_spec.execute(cursor, sql_, self)
     File "/home/superset/Personal/superset/superset/db_engine_specs/base.py", 
line 2224, in execute
       raise cls.get_dbapi_mapped_exception(ex) from ex
     File "/home/superset/Personal/superset/superset/db_engine_specs/base.py", 
line 2220, in execute
       cursor.execute(query)
   psycopg2.errors.UndefinedFunction: function date_trunc(unknown, character 
varying) does not exist
   LINE 1: SELECT DATE_TRUNC('day', event_timestamp) AS event_timestamp...
                  ^
   HINT:  No function matches the given name and argument types. You might need 
to add explicit type casts.
   
   2026-07-24 13:43:59,511:INFO:werkzeug:127.0.0.1 - - [24/Jul/2026 13:43:59] 
"POST /api/v1/chart/data HTTP/1.1" 400 -
   
   ### Checklist
   
   - [x] I have searched Superset docs and Slack and didn't find a solution to 
my problem.
   - [x] I have searched the GitHub issue tracker and didn't find a similar bug 
report.
   - [x] I have checked Superset's logs for errors and if I found a relevant 
Python stacktrace, I included it here as text in the "additional context" 
section.


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to