mirror of
https://github.com/home-assistant/core.git
synced 2025-08-10 08:05:06 +02:00
Adjust get_latest_short_term_statistics query to be postgresql compatible (#70953)
This commit is contained in:
@@ -1136,16 +1136,20 @@ def get_latest_short_term_statistics(
|
|||||||
]
|
]
|
||||||
most_recent_statistic_row = (
|
most_recent_statistic_row = (
|
||||||
session.query(
|
session.query(
|
||||||
StatisticsShortTerm.id,
|
StatisticsShortTerm.metadata_id,
|
||||||
func.max(StatisticsShortTerm.start),
|
func.max(StatisticsShortTerm.start).label("start_max"),
|
||||||
)
|
)
|
||||||
|
.filter(StatisticsShortTerm.metadata_id.in_(metadata_ids))
|
||||||
.group_by(StatisticsShortTerm.metadata_id)
|
.group_by(StatisticsShortTerm.metadata_id)
|
||||||
.having(StatisticsShortTerm.metadata_id.in_(metadata_ids))
|
|
||||||
).subquery()
|
).subquery()
|
||||||
stats = execute(
|
stats = execute(
|
||||||
session.query(*QUERY_STATISTICS_SHORT_TERM).join(
|
session.query(*QUERY_STATISTICS_SHORT_TERM).join(
|
||||||
most_recent_statistic_row,
|
most_recent_statistic_row,
|
||||||
StatisticsShortTerm.id == most_recent_statistic_row.c.id,
|
(
|
||||||
|
StatisticsShortTerm.metadata_id # pylint: disable=comparison-with-callable
|
||||||
|
== most_recent_statistic_row.c.metadata_id
|
||||||
|
)
|
||||||
|
& (StatisticsShortTerm.start == most_recent_statistic_row.c.start_max),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if not stats:
|
if not stats:
|
||||||
|
Reference in New Issue
Block a user