MySQL converting time to string (Grafana)

Viewed 4523

I am having a little trouble showing the number of times a user is running a SW version/HW version through Grafana. The following query works correctly in MySQL Workbench but when done in Grafana, the following error is given: Invalid type for column time/time_sec, must be of type timestamp or unix timestamp, got: string 1536692387

I have tried converting time_sec into a DATETIME type through CAST and CONVERT but have had no success. Does anyone have suggestions on how to handle this? Thank you.

Here is the current query (through workbench-the variables are defined in Grafana):

SET @$swVersion = 'LATEST';
SET @$hwString = 'TXT';

SELECT 
    IF(COUNT(user) > 0, epochStartTime, NOW()) AS time_sec,
    COUNT(user) AS 'John Doe'
FROM
    table
WHERE
    STRCMP(user, 'Name') = 0
    AND swVersion IN (@$swVersion)
    AND hwString IN (@$hwString)
1 Answers

Try this:

UNIX_TIMESTAMP(IF(COUNT(user) > 0, epochStartTime, NOW())) AS time_sec

in your query.

Related