Hello,
I just installed grafana and add a connection to an existing database with values based on mariadb 10.3.32-1040.
When adding the first simple query to a table the following error occurs:
db query error: Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘Load WHERE Timestamp BETWEEN FROM_UNIXTIME(1661854754) AND FROM_UNIXTIME(16…’ at line 4
The generated sql is:
SELECT
Timestamp AS "time",
Power
FROM Load
WHERE
$__timeFilter(Timestamp)
ORDER BY Timestamp
When I manually change this to the following, a graph will be displayed:
SELECT
Timestamp AS "time",
Power
FROM `PowerDb`.`Load`
WHERE
$__timeFilter(Timestamp)
ORDER BY Timestamp
Is there any solution to fix this error without change the query manually? When switching to query builder the database statement is missing and the query fails again.
I do not understand your question clearly. So your post title says that your query only works when mentioning the database name inside the SQL query.
But when looking into your SQL, I see that you are using 2 different tables i.e. PowerDB and Load to make it work, while using only a single table (i.e. Load) gave you an error as cannot show the results due to an incorrect query.
So where exactly did you mention the database name in your query manually?
OR I make a mistake in understanding your question?
Ok, I think I know this. Basically its the syntax thingy. So for e.g. I was doing this MySQL learning and on Grafana it does need to work like that i.e. db_name.table_name in the query.
So this is somewhat required for the query analyzer.
nope, it just helps us test it out on our side since we do not have access to your grafana
Some in this forum have power to read mind of people across the globe. I no longer have that capability.
Got it. ‘LOAD’ is a keyword. See LOAD DATA INFILE - MariaDB Knowledge Base
You didn’t choose suitable table name, so you have to always specify this long db.table format explicitly, so DB knows that LOAD is a table and not a SQL command.