I’m having this error in the logs.
I’m right now with the recorder pointing to an external MySQL server, as in my RPi it “kills” the IO output.
Any idea about how to fix it?
Is it a bug?
FROM (SELECT statistics_short_term.metadata_id AS metadata_id, statistics_short_term.start AS start, statistics_short_term.last_reset AS last_reset, statistics_short_term.state AS state, statistics_short_term.sum AS sum, row_number() OVER (PARTITION BY statistics_short_term.metadata_id ORDER BY statistics_short_term.start DESC) AS rownum
FROM statistics_short_term
WHERE statistics_short_term.start >= %s AND statistics_short_term.start < %s) AS anon_1
WHERE anon_1.rownum = %s ORDER BY anon_1.metadata_id]
[parameters: (datetime.datetime(2021, 10, 6, 17, 0, tzinfo=datetime.timezone.utc), datetime.datetime(2021, 10, 6, 18, 0, tzinfo=datetime.timezone.utc), 1)]
(Background on this error at: https://sqlalche.me/e/14/f405)
2021-10-06 20:23:58 ERROR (Recorder) [homeassistant.components.recorder.util] Error executing query: (MySQLdb._exceptions.ProgrammingError) (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(PARTITION BY statistics_short_term.metadata_id ORDER BY statistics_short_term.s' at line 2")
[SQL: SELECT anon_1.metadata_id AS anon_1_metadata_id, anon_1.start AS anon_1_start, anon_1.last_reset AS anon_1_last_reset, anon_1.state AS anon_1_state, anon_1.sum AS anon_1_sum, anon_1.rownum AS anon_1_rownum
FROM (SELECT statistics_short_term.metadata_id AS metadata_id, statistics_short_term.start AS start, statistics_short_term.last_reset AS last_reset, statistics_short_term.state AS state, statistics_short_term.sum AS sum, row_number() OVER (PARTITION BY statistics_short_term.metadata_id ORDER BY statistics_short_term.start DESC) AS rownum
FROM statistics_short_term
WHERE statistics_short_term.start >= %s AND statistics_short_term.start < %s) AS anon_1
WHERE anon_1.rownum = %s ORDER BY anon_1.metadata_id]
[parameters: (datetime.datetime(2021, 10, 6, 17, 0, tzinfo=datetime.timezone.utc), datetime.datetime(2021, 10, 6, 18, 0, tzinfo=datetime.timezone.utc), 1)]
(Background on this error at: https://sqlalche.me/e/14/f405)
2021-10-06 20:23:58 ERROR (Recorder) [homeassistant.components.recorder.util] Error executing query: (MySQLdb._exceptions.ProgrammingError) (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(PARTITION BY statistics_short_term.metadata_id ORDER BY statistics_short_term.s' at line 2")
[SQL: SELECT anon_1.metadata_id AS anon_1_metadata_id, anon_1.start AS anon_1_start, anon_1.last_reset AS anon_1_last_reset, anon_1.state AS anon_1_state, anon_1.sum AS anon_1_sum, anon_1.rownum AS anon_1_rownum
FROM (SELECT statistics_short_term.metadata_id AS metadata_id, statistics_short_term.start AS start, statistics_short_term.last_reset AS last_reset, statistics_short_term.state AS state, statistics_short_term.sum AS sum, row_number() OVER (PARTITION BY statistics_short_term.metadata_id ORDER BY statistics_short_term.start DESC) AS rownum
FROM statistics_short_term
WHERE statistics_short_term.start >= %s AND statistics_short_term.start < %s) AS anon_1
WHERE anon_1.rownum = %s ORDER BY anon_1.metadata_id]
[parameters: (datetime.datetime(2021, 10, 6, 17, 0, tzinfo=datetime.timezone.utc), datetime.datetime(2021, 10, 6, 18, 0, tzinfo=datetime.timezone.utc), 1)]
(Background on this error at: https://sqlalche.me/e/14/f405)
2021-10-06 20:23:59 ERROR (Recorder) [homeassistant.components.recorder] Unhandled database error while processing event StatisticsTask(start=datetime.datetime(2021, 10, 6, 17, 55, tzinfo=datetime.timezone.utc)): (MySQLdb._exceptions.ProgrammingError) (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(PARTITION BY statistics_short_term.metadata_id ORDER BY statistics_short_term.s' at line 2")
[SQL: SELECT anon_1.metadata_id AS anon_1_metadata_id, anon_1.start AS anon_1_start, anon_1.last_reset AS anon_1_last_reset, anon_1.state AS anon_1_state, anon_1.sum AS anon_1_sum, anon_1.rownum AS anon_1_rownum
FROM (SELECT statistics_short_term.metadata_id AS metadata_id, statistics_short_term.start AS start, statistics_short_term.last_reset AS last_reset, statistics_short_term.state AS state, statistics_short_term.sum AS sum, row_number() OVER (PARTITION BY statistics_short_term.metadata_id ORDER BY statistics_short_term.start DESC) AS rownum
FROM statistics_short_term
WHERE statistics_short_term.start >= %s AND statistics_short_term.start < %s) AS anon_1
WHERE anon_1.rownum = %s ORDER BY anon_1.metadata_id]
[parameters: (datetime.datetime(2021, 10, 6, 17, 0, tzinfo=datetime.timezone.utc), datetime.datetime(2021, 10, 6, 18, 0, tzinfo=datetime.timezone.utc), 1)]
(Background on this error at: https://sqlalche.me/e/14/f405)
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1771, in _execute_context
self.dialect.do_execute(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 717, in do_execute
cursor.execute(statement, parameters)
File "/usr/local/lib/python3.9/site-packages/MySQLdb/cursors.py", line 206, in execute
res = self._query(query)
File "/usr/local/lib/python3.9/site-packages/MySQLdb/cursors.py", line 319, in _query
db.query(q)
File "/usr/local/lib/python3.9/site-packages/MySQLdb/connections.py", line 259, in query
_mysql.connection.query(self, query)
MySQLdb._exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(PARTITION BY statistics_short_term.metadata_id ORDER BY statistics_short_term.s' at line 2")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/recorder/__init__.py", line 682, in _process_one_event_or_recover
self._process_one_event(event)
File "/usr/src/homeassistant/homeassistant/components/recorder/__init__.py", line 788, in _process_one_event
self._run_statistics(event.start)
File "/usr/src/homeassistant/homeassistant/components/recorder/__init__.py", line 771, in _run_statistics
if statistics.compile_statistics(self, start):
File "/usr/src/homeassistant/homeassistant/components/recorder/util.py", line 315, in wrapper
return job(instance, *args, **kwargs)
File "/usr/src/homeassistant/homeassistant/components/recorder/statistics.py", line 357, in compile_statistics
compile_hourly_statistics(instance, session, start)
File "/usr/src/homeassistant/homeassistant/components/recorder/statistics.py", line 288, in compile_hourly_statistics
stats = execute(query.params(start_time=start_time, end_time=end_time))
File "/usr/src/homeassistant/homeassistant/components/recorder/util.py", line 116, in execute
result = list(qry)
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/query.py", line 2839, in __iter__
return self._iter().__iter__()
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/query.py", line 2846, in _iter
result = self.session.execute(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 1689, in execute
result = conn._execute_20(statement, params or {}, execution_options)
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1583, in _execute_20
return meth(self, args_10style, kwargs_10style, execution_options)
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/sql/elements.py", line 323, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1452, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1814, in _execute_context
self._handle_dbapi_exception(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1995, in _handle_dbapi_exception
util.raise_(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 207, in raise_
raise exception
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1771, in _execute_context
self.dialect.do_execute(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 717, in do_execute
cursor.execute(statement, parameters)
File "/usr/local/lib/python3.9/site-packages/MySQLdb/cursors.py", line 206, in execute
res = self._query(query)
File "/usr/local/lib/python3.9/site-packages/MySQLdb/cursors.py", line 319, in _query
db.query(q)
File "/usr/local/lib/python3.9/site-packages/MySQLdb/connections.py", line 259, in query
_mysql.connection.query(self, query)
sqlalchemy.exc.ProgrammingError: (MySQLdb._exceptions.ProgrammingError) (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(PARTITION BY statistics_short_term.metadata_id ORDER BY statistics_short_term.s' at line 2")
[SQL: SELECT anon_1.metadata_id AS anon_1_metadata_id, anon_1.start AS anon_1_start, anon_1.last_reset AS anon_1_last_reset, anon_1.state AS anon_1_state, anon_1.sum AS anon_1_sum, anon_1.rownum AS anon_1_rownum
FROM (SELECT statistics_short_term.metadata_id AS metadata_id, statistics_short_term.start AS start, statistics_short_term.last_reset AS last_reset, statistics_short_term.state AS state, statistics_short_term.sum AS sum, row_number() OVER (PARTITION BY statistics_short_term.metadata_id ORDER BY statistics_short_term.start DESC) AS rownum
FROM statistics_short_term
WHERE statistics_short_term.start >= %s AND statistics_short_term.start < %s) AS anon_1
WHERE anon_1.rownum = %s ORDER BY anon_1.metadata_id]
[parameters: (datetime.datetime(2021, 10, 6, 17, 0, tzinfo=datetime.timezone.utc), datetime.datetime(2021, 10, 6, 18, 0, tzinfo=datetime.timezone.utc), 1)]
(Background on this error at: https://sqlalche.me/e/14/f405)
Another log a few minutes after:
2021-10-06 21:15:55 ERROR (Recorder) [homeassistant.components.recorder.util] Error executing query: (MySQLdb._exceptions.ProgrammingError) (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(PARTITION BY statistics_short_term.metadata_id ORDER BY statistics_short_term.s' at line 2")
[SQL: SELECT anon_1.metadata_id AS anon_1_metadata_id, anon_1.start AS anon_1_start, anon_1.last_reset AS anon_1_last_reset, anon_1.state AS anon_1_state, anon_1.sum AS anon_1_sum, anon_1.rownum AS anon_1_rownum
FROM (SELECT statistics_short_term.metadata_id AS metadata_id, statistics_short_term.start AS start, statistics_short_term.last_reset AS last_reset, statistics_short_term.state AS state, statistics_short_term.sum AS sum, row_number() OVER (PARTITION BY statistics_short_term.metadata_id ORDER BY statistics_short_term.start DESC) AS rownum
FROM statistics_short_term
WHERE statistics_short_term.start >= %s AND statistics_short_term.start < %s) AS anon_1
WHERE anon_1.rownum = %s ORDER BY anon_1.metadata_id]
[parameters: (datetime.datetime(2021, 10, 6, 18, 0, tzinfo=datetime.timezone.utc), datetime.datetime(2021, 10, 6, 19, 0, tzinfo=datetime.timezone.utc), 1)]
(Background on this error at: https://sqlalche.me/e/14/f405)
2021-10-06 21:15:56 ERROR (Recorder) [homeassistant.components.recorder.util] Error executing query: (MySQLdb._exceptions.ProgrammingError) (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(PARTITION BY statistics_short_term.metadata_id ORDER BY statistics_short_term.s' at line 2")
[SQL: SELECT anon_1.metadata_id AS anon_1_metadata_id, anon_1.start AS anon_1_start, anon_1.last_reset AS anon_1_last_reset, anon_1.state AS anon_1_state, anon_1.sum AS anon_1_sum, anon_1.rownum AS anon_1_rownum
FROM (SELECT statistics_short_term.metadata_id AS metadata_id, statistics_short_term.start AS start, statistics_short_term.last_reset AS last_reset, statistics_short_term.state AS state, statistics_short_term.sum AS sum, row_number() OVER (PARTITION BY statistics_short_term.metadata_id ORDER BY statistics_short_term.start DESC) AS rownum
FROM statistics_short_term
WHERE statistics_short_term.start >= %s AND statistics_short_term.start < %s) AS anon_1
WHERE anon_1.rownum = %s ORDER BY anon_1.metadata_id]
[parameters: (datetime.datetime(2021, 10, 6, 18, 0, tzinfo=datetime.timezone.utc), datetime.datetime(2021, 10, 6, 19, 0, tzinfo=datetime.timezone.utc), 1)]
(Background on this error at: https://sqlalche.me/e/14/f405)
2021-10-06 21:15:56 ERROR (Recorder) [homeassistant.components.recorder.util] Error executing query: (MySQLdb._exceptions.ProgrammingError) (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(PARTITION BY statistics_short_term.metadata_id ORDER BY statistics_short_term.s' at line 2")
[SQL: SELECT anon_1.metadata_id AS anon_1_metadata_id, anon_1.start AS anon_1_start, anon_1.last_reset AS anon_1_last_reset, anon_1.state AS anon_1_state, anon_1.sum AS anon_1_sum, anon_1.rownum AS anon_1_rownum
FROM (SELECT statistics_short_term.metadata_id AS metadata_id, statistics_short_term.start AS start, statistics_short_term.last_reset AS last_reset, statistics_short_term.state AS state, statistics_short_term.sum AS sum, row_number() OVER (PARTITION BY statistics_short_term.metadata_id ORDER BY statistics_short_term.start DESC) AS rownum
FROM statistics_short_term
WHERE statistics_short_term.start >= %s AND statistics_short_term.start < %s) AS anon_1
WHERE anon_1.rownum = %s ORDER BY anon_1.metadata_id]
[parameters: (datetime.datetime(2021, 10, 6, 18, 0, tzinfo=datetime.timezone.utc), datetime.datetime(2021, 10, 6, 19, 0, tzinfo=datetime.timezone.utc), 1)]
(Background on this error at: https://sqlalche.me/e/14/f405)
2021-10-06 21:15:56 ERROR (Recorder) [homeassistant.components.recorder] Unhandled database error while processing event StatisticsTask(start=datetime.datetime(2021, 10, 6, 18, 55, tzinfo=datetime.timezone.utc)): (MySQLdb._exceptions.ProgrammingError) (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(PARTITION BY statistics_short_term.metadata_id ORDER BY statistics_short_term.s' at line 2")
[SQL: SELECT anon_1.metadata_id AS anon_1_metadata_id, anon_1.start AS anon_1_start, anon_1.last_reset AS anon_1_last_reset, anon_1.state AS anon_1_state, anon_1.sum AS anon_1_sum, anon_1.rownum AS anon_1_rownum
FROM (SELECT statistics_short_term.metadata_id AS metadata_id, statistics_short_term.start AS start, statistics_short_term.last_reset AS last_reset, statistics_short_term.state AS state, statistics_short_term.sum AS sum, row_number() OVER (PARTITION BY statistics_short_term.metadata_id ORDER BY statistics_short_term.start DESC) AS rownum
FROM statistics_short_term
WHERE statistics_short_term.start >= %s AND statistics_short_term.start < %s) AS anon_1
WHERE anon_1.rownum = %s ORDER BY anon_1.metadata_id]
[parameters: (datetime.datetime(2021, 10, 6, 18, 0, tzinfo=datetime.timezone.utc), datetime.datetime(2021, 10, 6, 19, 0, tzinfo=datetime.timezone.utc), 1)]
(Background on this error at: https://sqlalche.me/e/14/f405)
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1771, in _execute_context
self.dialect.do_execute(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 717, in do_execute
cursor.execute(statement, parameters)
File "/usr/local/lib/python3.9/site-packages/MySQLdb/cursors.py", line 206, in execute
res = self._query(query)
File "/usr/local/lib/python3.9/site-packages/MySQLdb/cursors.py", line 319, in _query
db.query(q)
File "/usr/local/lib/python3.9/site-packages/MySQLdb/connections.py", line 259, in query
_mysql.connection.query(self, query)
MySQLdb._exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(PARTITION BY statistics_short_term.metadata_id ORDER BY statistics_short_term.s' at line 2")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/recorder/__init__.py", line 682, in _process_one_event_or_recover
self._process_one_event(event)
File "/usr/src/homeassistant/homeassistant/components/recorder/__init__.py", line 788, in _process_one_event
self._run_statistics(event.start)
File "/usr/src/homeassistant/homeassistant/components/recorder/__init__.py", line 771, in _run_statistics
if statistics.compile_statistics(self, start):
File "/usr/src/homeassistant/homeassistant/components/recorder/util.py", line 315, in wrapper
return job(instance, *args, **kwargs)
File "/usr/src/homeassistant/homeassistant/components/recorder/statistics.py", line 357, in compile_statistics
compile_hourly_statistics(instance, session, start)
File "/usr/src/homeassistant/homeassistant/components/recorder/statistics.py", line 288, in compile_hourly_statistics
stats = execute(query.params(start_time=start_time, end_time=end_time))
File "/usr/src/homeassistant/homeassistant/components/recorder/util.py", line 116, in execute
result = list(qry)
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/query.py", line 2839, in __iter__
return self._iter().__iter__()
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/query.py", line 2846, in _iter
result = self.session.execute(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 1689, in execute
result = conn._execute_20(statement, params or {}, execution_options)
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1583, in _execute_20
return meth(self, args_10style, kwargs_10style, execution_options)
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/sql/elements.py", line 323, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1452, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1814, in _execute_context
self._handle_dbapi_exception(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1995, in _handle_dbapi_exception
util.raise_(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 207, in raise_
raise exception
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1771, in _execute_context
self.dialect.do_execute(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 717, in do_execute
cursor.execute(statement, parameters)
File "/usr/local/lib/python3.9/site-packages/MySQLdb/cursors.py", line 206, in execute
res = self._query(query)
File "/usr/local/lib/python3.9/site-packages/MySQLdb/cursors.py", line 319, in _query
db.query(q)
File "/usr/local/lib/python3.9/site-packages/MySQLdb/connections.py", line 259, in query
_mysql.connection.query(self, query)
sqlalchemy.exc.ProgrammingError: (MySQLdb._exceptions.ProgrammingError) (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(PARTITION BY statistics_short_term.metadata_id ORDER BY statistics_short_term.s' at line 2")
[SQL: SELECT anon_1.metadata_id AS anon_1_metadata_id, anon_1.start AS anon_1_start, anon_1.last_reset AS anon_1_last_reset, anon_1.state AS anon_1_state, anon_1.sum AS anon_1_sum, anon_1.rownum AS anon_1_rownum
FROM (SELECT statistics_short_term.metadata_id AS metadata_id, statistics_short_term.start AS start, statistics_short_term.last_reset AS last_reset, statistics_short_term.state AS state, statistics_short_term.sum AS sum, row_number() OVER (PARTITION BY statistics_short_term.metadata_id ORDER BY statistics_short_term.start DESC) AS rownum
FROM statistics_short_term
WHERE statistics_short_term.start >= %s AND statistics_short_term.start < %s) AS anon_1
WHERE anon_1.rownum = %s ORDER BY anon_1.metadata_id]
[parameters: (datetime.datetime(2021, 10, 6, 18, 0, tzinfo=datetime.timezone.utc), datetime.datetime(2021, 10, 6, 19, 0, tzinfo=datetime.timezone.utc), 1)]
(Background on this error at: https://sqlalche.me/e/14/f405)