Make sure these boxes are checked before submitting your issue - thank you!

- [x] I have checked the superset logs for python stacktraces and included it 
here as text if any
- [x] I have reproduced the issue with at least the latest released version of 
superset
- [x] I have checked the issue tracker for the same issue and I haven't found 
one similar

### Superset version
27

### Expected results
My database table column 'timeperiod' is BIGINT type. When I want to use Time 
Grain in Time Series, I choose this. 
I think SQL will be 

```
SELECT DATE_TRUNC('day', to_timestamp(timeperiod/1000)) AT TIME ZONE 'UTC' AS 
__timestamp,
                                                                                
                       SUM(attackdegree) AS "SUM(attackdegree)"
FROM macchain
WHERE to_char(to_timestamp(timeperiod/1000), 'yyyy-mm-dd HH24:MI:SS') >= 
'2018-09-05 00:00:00'
  AND to_char(to_timestamp(timeperiod/1000), 'yyyy-mm-dd HH24:MI:SS') <= 
'2018-09-12 09:08:06'
GROUP BY DATE_TRUNC('day', to_char(to_timestamp(timeperiod/1000), 'yyyy-mm-dd 
HH24:MI:SS')) AT TIME ZONE 'UTC'
ORDER BY "SUM(attackdegree)" DESC
LIMIT 50000;
```


### Actual results
Why is the function 'to_char()' in the SQL statement?  The date_trunc() second 
argument should be timestamp 

```
SELECT DATE_TRUNC('day', to_char(to_timestamp(timeperiod/1000), 'yyyy-mm-dd 
HH24:MI:SS')) AT TIME ZONE 'UTC' AS __timestamp,
                                                                                
                       SUM(attackdegree) AS "SUM(attackdegree)"
FROM macchain
WHERE to_char(to_timestamp(timeperiod/1000), 'yyyy-mm-dd HH24:MI:SS') >= 
'2018-09-05 00:00:00'
  AND to_char(to_timestamp(timeperiod/1000), 'yyyy-mm-dd HH24:MI:SS') <= 
'2018-09-12 09:08:06'
GROUP BY DATE_TRUNC('day', to_char(to_timestamp(timeperiod/1000), 'yyyy-mm-dd 
HH24:MI:SS')) AT TIME ZONE 'UTC'
ORDER BY "SUM(attackdegree)" DESC
LIMIT 50000;
```
![image](https://user-images.githubusercontent.com/12036023/45412880-68939c80-b6aa-11e8-8d00-1bb94fdd2e21.png)



### Steps to reproduce
Time Series Chart
Time Colum (timeperiod  BIGINT)   Time Grain (day) 
ERROR:
(psycopg2.ProgrammingError) function date_trunc(unknown, text) does not exist 
LINE 1: SELECT DATE_TRUNC('day', to_char(to_timestamp(timeperiod/100... ^ HINT: 
No function matches the given name and argument types. You might need to add 
explicit type casts. [SQL: 'SELECT DATE_TRUNC(\'day\', 
to_char(to_timestamp(timeperiod/1000), \'yyyy-mm-dd HH24:MI:SS\')) AT TIME ZONE 
\'UTC\' AS __timestamp,\n SUM(attackdegree) AS "SUM(attackdegree)"\nFROM 
macchain\nWHERE to_char(to_timestamp(timeperiod/1000), \'yyyy-mm-dd 
HH24:MI:SS\') >= \'2018-09-05 00:00:00\'\n AND 
to_char(to_timestamp(timeperiod/1000), \'yyyy-mm-dd HH24:MI:SS\') <= 
\'2018-09-12 09:08:06\'\nGROUP BY DATE_TRUNC(\'day\', 
to_char(to_timestamp(timeperiod/1000), \'yyyy-mm-dd HH24:MI:SS\')) AT TIME ZONE 
\'UTC\'\nORDER BY "SUM(attackdegree)" DESC\nLIMIT 50000'] (Background on this 
error at: http://sqlalche.me/e/f405)


[ Full content available at: 
https://github.com/apache/incubator-superset/issues/5871 ]
This message was relayed via gitbox.apache.org for [email protected]

Reply via email to