mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Adjust get_latest_short_term_statistics query to be postgresql compatible (#70953)
This commit is contained in:
parent
79c9d22893
commit
27a4a9eed4
@ -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:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user