Home Assistant Unofficial Reference 2024.12.1
homeassistant.components.recorder.queries Namespace Reference

Functions

Select _event_data_id_exist (int|None data_id)
 
Select _state_attrs_exist (int|None attr)
 
StatementLambdaElement attributes_ids_exist_in_states (int attr1, int|None attr2, int|None attr3, int|None attr4, int|None attr5, int|None attr6, int|None attr7, int|None attr8, int|None attr9, int|None attr10, int|None attr11, int|None attr12, int|None attr13, int|None attr14, int|None attr15, int|None attr16, int|None attr17, int|None attr18, int|None attr19, int|None attr20, int|None attr21, int|None attr22, int|None attr23, int|None attr24, int|None attr25, int|None attr26, int|None attr27, int|None attr28, int|None attr29, int|None attr30, int|None attr31, int|None attr32, int|None attr33, int|None attr34, int|None attr35, int|None attr36, int|None attr37, int|None attr38, int|None attr39, int|None attr40, int|None attr41, int|None attr42, int|None attr43, int|None attr44, int|None attr45, int|None attr46, int|None attr47, int|None attr48, int|None attr49, int|None attr50, int|None attr51, int|None attr52, int|None attr53, int|None attr54, int|None attr55, int|None attr56, int|None attr57, int|None attr58, int|None attr59, int|None attr60, int|None attr61, int|None attr62, int|None attr63, int|None attr64, int|None attr65, int|None attr66, int|None attr67, int|None attr68, int|None attr69, int|None attr70, int|None attr71, int|None attr72, int|None attr73, int|None attr74, int|None attr75, int|None attr76, int|None attr77, int|None attr78, int|None attr79, int|None attr80, int|None attr81, int|None attr82, int|None attr83, int|None attr84, int|None attr85, int|None attr86, int|None attr87, int|None attr88, int|None attr89, int|None attr90, int|None attr91, int|None attr92, int|None attr93, int|None attr94, int|None attr95, int|None attr96, int|None attr97, int|None attr98, int|None attr99, int|None attr100)
 
StatementLambdaElement attributes_ids_exist_in_states_with_fast_in_distinct (Iterable[int] attributes_ids)
 
StatementLambdaElement batch_cleanup_entity_ids ()
 
StatementLambdaElement data_ids_exist_in_events (int id1, int|None id2, int|None id3, int|None id4, int|None id5, int|None id6, int|None id7, int|None id8, int|None id9, int|None id10, int|None id11, int|None id12, int|None id13, int|None id14, int|None id15, int|None id16, int|None id17, int|None id18, int|None id19, int|None id20, int|None id21, int|None id22, int|None id23, int|None id24, int|None id25, int|None id26, int|None id27, int|None id28, int|None id29, int|None id30, int|None id31, int|None id32, int|None id33, int|None id34, int|None id35, int|None id36, int|None id37, int|None id38, int|None id39, int|None id40, int|None id41, int|None id42, int|None id43, int|None id44, int|None id45, int|None id46, int|None id47, int|None id48, int|None id49, int|None id50, int|None id51, int|None id52, int|None id53, int|None id54, int|None id55, int|None id56, int|None id57, int|None id58, int|None id59, int|None id60, int|None id61, int|None id62, int|None id63, int|None id64, int|None id65, int|None id66, int|None id67, int|None id68, int|None id69, int|None id70, int|None id71, int|None id72, int|None id73, int|None id74, int|None id75, int|None id76, int|None id77, int|None id78, int|None id79, int|None id80, int|None id81, int|None id82, int|None id83, int|None id84, int|None id85, int|None id86, int|None id87, int|None id88, int|None id89, int|None id90, int|None id91, int|None id92, int|None id93, int|None id94, int|None id95, int|None id96, int|None id97, int|None id98, int|None id99, int|None id100)
 
StatementLambdaElement data_ids_exist_in_events_with_fast_in_distinct (Iterable[int] data_ids)
 
StatementLambdaElement delete_duplicate_short_term_statistics_row (int statistic_id)
 
StatementLambdaElement delete_duplicate_statistics_row (int statistic_id)
 
StatementLambdaElement delete_event_data_rows (Iterable[int] data_ids)
 
StatementLambdaElement delete_event_rows (Iterable[int] event_ids)
 
StatementLambdaElement delete_event_types_rows (Iterable[int] event_type_ids)
 
StatementLambdaElement delete_recorder_runs_rows (datetime purge_before, int current_run_id)
 
StatementLambdaElement delete_states_attributes_rows (Iterable[int] attributes_ids)
 
StatementLambdaElement delete_states_meta_rows (Iterable[int] metadata_ids)
 
StatementLambdaElement delete_states_rows (Iterable[int] state_ids)
 
StatementLambdaElement delete_statistics_runs_rows (Iterable[int] statistics_runs)
 
StatementLambdaElement delete_statistics_short_term_rows (Iterable[int] short_term_statistics)
 
StatementLambdaElement disconnect_states_rows (Iterable[int] state_ids)
 
StatementLambdaElement find_all_states_metadata_ids ()
 
StatementLambdaElement find_entity_ids_to_migrate (int max_bind_vars)
 
StatementLambdaElement find_entity_ids_to_purge ()
 
StatementLambdaElement find_event_type_ids (Iterable[str] event_types)
 
StatementLambdaElement find_event_type_to_migrate (int max_bind_vars)
 
StatementLambdaElement find_event_types_to_purge ()
 
StatementLambdaElement find_events_context_ids_to_migrate (int max_bind_vars)
 
StatementLambdaElement find_events_to_purge (float purge_before, int max_bind_vars)
 
StatementLambdaElement find_latest_statistics_runs_run_id ()
 
StatementLambdaElement find_legacy_detached_states_and_attributes_to_purge (float purge_before, int max_bind_vars)
 
StatementLambdaElement find_legacy_event_state_and_attributes_and_data_ids_to_purge (float purge_before, int max_bind_vars)
 
StatementLambdaElement find_legacy_row ()
 
StatementLambdaElement find_oldest_state ()
 
StatementLambdaElement find_short_term_statistics_to_purge (datetime purge_before, int max_bind_vars)
 
StatementLambdaElement find_states_context_ids_to_migrate (int max_bind_vars)
 
StatementLambdaElement find_states_metadata_ids (Iterable[str] entity_ids)
 
StatementLambdaElement find_states_to_purge (float purge_before, int max_bind_vars)
 
StatementLambdaElement find_statistics_runs_to_purge (datetime purge_before, int max_bind_vars)
 
StatementLambdaElement find_unmigrated_short_term_statistics_rows (int max_bind_vars)
 
StatementLambdaElement find_unmigrated_statistics_rows (int max_bind_vars)
 
StatementLambdaElement get_migration_changes ()
 
StatementLambdaElement get_shared_attributes (list[int] hashes)
 
StatementLambdaElement get_shared_event_datas (list[int] hashes)
 
StatementLambdaElement has_entity_ids_to_migrate ()
 
StatementLambdaElement has_event_type_to_migrate ()
 
StatementLambdaElement has_events_context_ids_to_migrate ()
 
StatementLambdaElement has_states_context_ids_to_migrate ()
 
StatementLambdaElement has_used_states_entity_ids ()
 
StatementLambdaElement has_used_states_event_ids ()
 
StatementLambdaElement migrate_single_short_term_statistics_row_to_timestamp (int statistic_id, float|None start_ts, float|None created_ts, float|None last_reset_ts)
 
StatementLambdaElement migrate_single_statistics_row_to_timestamp (int statistic_id, float|None start_ts, float|None created_ts, float|None last_reset_ts)
 
Select select_event_type_ids (tuple[str,...] event_types)
 

Detailed Description

Queries for the recorder.

Function Documentation

◆ _event_data_id_exist()

Select homeassistant.components.recorder.queries._event_data_id_exist ( int | None  data_id)
private
Check if a event data id exists in the events table.

Definition at line 316 of file queries.py.

◆ _state_attrs_exist()

Select homeassistant.components.recorder.queries._state_attrs_exist ( int | None  attr)
private
Check if a state attributes id exists in the states table.

Definition at line 79 of file queries.py.

◆ attributes_ids_exist_in_states()

StatementLambdaElement homeassistant.components.recorder.queries.attributes_ids_exist_in_states ( int  attr1,
int | None  attr2,
int | None  attr3,
int | None  attr4,
int | None  attr5,
int | None  attr6,
int | None  attr7,
int | None  attr8,
int | None  attr9,
int | None  attr10,
int | None  attr11,
int | None  attr12,
int | None  attr13,
int | None  attr14,
int | None  attr15,
int | None  attr16,
int | None  attr17,
int | None  attr18,
int | None  attr19,
int | None  attr20,
int | None  attr21,
int | None  attr22,
int | None  attr23,
int | None  attr24,
int | None  attr25,
int | None  attr26,
int | None  attr27,
int | None  attr28,
int | None  attr29,
int | None  attr30,
int | None  attr31,
int | None  attr32,
int | None  attr33,
int | None  attr34,
int | None  attr35,
int | None  attr36,
int | None  attr37,
int | None  attr38,
int | None  attr39,
int | None  attr40,
int | None  attr41,
int | None  attr42,
int | None  attr43,
int | None  attr44,
int | None  attr45,
int | None  attr46,
int | None  attr47,
int | None  attr48,
int | None  attr49,
int | None  attr50,
int | None  attr51,
int | None  attr52,
int | None  attr53,
int | None  attr54,
int | None  attr55,
int | None  attr56,
int | None  attr57,
int | None  attr58,
int | None  attr59,
int | None  attr60,
int | None  attr61,
int | None  attr62,
int | None  attr63,
int | None  attr64,
int | None  attr65,
int | None  attr66,
int | None  attr67,
int | None  attr68,
int | None  attr69,
int | None  attr70,
int | None  attr71,
int | None  attr72,
int | None  attr73,
int | None  attr74,
int | None  attr75,
int | None  attr76,
int | None  attr77,
int | None  attr78,
int | None  attr79,
int | None  attr80,
int | None  attr81,
int | None  attr82,
int | None  attr83,
int | None  attr84,
int | None  attr85,
int | None  attr86,
int | None  attr87,
int | None  attr88,
int | None  attr89,
int | None  attr90,
int | None  attr91,
int | None  attr92,
int | None  attr93,
int | None  attr94,
int | None  attr95,
int | None  attr96,
int | None  attr97,
int | None  attr98,
int | None  attr99,
int | None  attr100 
)
Generate the find attributes select only once.

https://docs.sqlalchemy.org/en/14/core/connections.html#quick-guidelines-for-lambdas

Definition at line 95 of file queries.py.

◆ attributes_ids_exist_in_states_with_fast_in_distinct()

StatementLambdaElement homeassistant.components.recorder.queries.attributes_ids_exist_in_states_with_fast_in_distinct ( Iterable[int]  attributes_ids)
Find attributes ids that exist in the states table.

Definition at line 84 of file queries.py.

◆ batch_cleanup_entity_ids()

StatementLambdaElement homeassistant.components.recorder.queries.batch_cleanup_entity_ids ( )
Find entity_id to cleanup.

Definition at line 751 of file queries.py.

◆ data_ids_exist_in_events()

StatementLambdaElement homeassistant.components.recorder.queries.data_ids_exist_in_events ( int  id1,
int | None  id2,
int | None  id3,
int | None  id4,
int | None  id5,
int | None  id6,
int | None  id7,
int | None  id8,
int | None  id9,
int | None  id10,
int | None  id11,
int | None  id12,
int | None  id13,
int | None  id14,
int | None  id15,
int | None  id16,
int | None  id17,
int | None  id18,
int | None  id19,
int | None  id20,
int | None  id21,
int | None  id22,
int | None  id23,
int | None  id24,
int | None  id25,
int | None  id26,
int | None  id27,
int | None  id28,
int | None  id29,
int | None  id30,
int | None  id31,
int | None  id32,
int | None  id33,
int | None  id34,
int | None  id35,
int | None  id36,
int | None  id37,
int | None  id38,
int | None  id39,
int | None  id40,
int | None  id41,
int | None  id42,
int | None  id43,
int | None  id44,
int | None  id45,
int | None  id46,
int | None  id47,
int | None  id48,
int | None  id49,
int | None  id50,
int | None  id51,
int | None  id52,
int | None  id53,
int | None  id54,
int | None  id55,
int | None  id56,
int | None  id57,
int | None  id58,
int | None  id59,
int | None  id60,
int | None  id61,
int | None  id62,
int | None  id63,
int | None  id64,
int | None  id65,
int | None  id66,
int | None  id67,
int | None  id68,
int | None  id69,
int | None  id70,
int | None  id71,
int | None  id72,
int | None  id73,
int | None  id74,
int | None  id75,
int | None  id76,
int | None  id77,
int | None  id78,
int | None  id79,
int | None  id80,
int | None  id81,
int | None  id82,
int | None  id83,
int | None  id84,
int | None  id85,
int | None  id86,
int | None  id87,
int | None  id88,
int | None  id89,
int | None  id90,
int | None  id91,
int | None  id92,
int | None  id93,
int | None  id94,
int | None  id95,
int | None  id96,
int | None  id97,
int | None  id98,
int | None  id99,
int | None  id100 
)
Generate the find event data select only once.

https://docs.sqlalchemy.org/en/14/core/connections.html#quick-guidelines-for-lambdas

Definition at line 321 of file queries.py.

◆ data_ids_exist_in_events_with_fast_in_distinct()

StatementLambdaElement homeassistant.components.recorder.queries.data_ids_exist_in_events_with_fast_in_distinct ( Iterable[int]  data_ids)
Find data ids that exist in the events table.

Definition at line 307 of file queries.py.

◆ delete_duplicate_short_term_statistics_row()

StatementLambdaElement homeassistant.components.recorder.queries.delete_duplicate_short_term_statistics_row ( int  statistic_id)
Delete a single duplicate short term statistics row.

Definition at line 965 of file queries.py.

◆ delete_duplicate_statistics_row()

StatementLambdaElement homeassistant.components.recorder.queries.delete_duplicate_statistics_row ( int  statistic_id)
Delete a single duplicate statistics row.

Definition at line 976 of file queries.py.

◆ delete_event_data_rows()

StatementLambdaElement homeassistant.components.recorder.queries.delete_event_data_rows ( Iterable[int]  data_ids)
Delete event_data rows.

Definition at line 552 of file queries.py.

◆ delete_event_rows()

StatementLambdaElement homeassistant.components.recorder.queries.delete_event_rows ( Iterable[int]  event_ids)
Delete event rows.

Definition at line 594 of file queries.py.

◆ delete_event_types_rows()

StatementLambdaElement homeassistant.components.recorder.queries.delete_event_types_rows ( Iterable[int]  event_type_ids)
Delete EventTypes rows.

Definition at line 874 of file queries.py.

◆ delete_recorder_runs_rows()

StatementLambdaElement homeassistant.components.recorder.queries.delete_recorder_runs_rows ( datetime  purge_before,
int   current_run_id 
)
Delete recorder_runs rows.

Definition at line 605 of file queries.py.

◆ delete_states_attributes_rows()

StatementLambdaElement homeassistant.components.recorder.queries.delete_states_attributes_rows ( Iterable[int]  attributes_ids)
Delete states_attributes rows.

Definition at line 561 of file queries.py.

◆ delete_states_meta_rows()

StatementLambdaElement homeassistant.components.recorder.queries.delete_states_meta_rows ( Iterable[int]  metadata_ids)
Delete StatesMeta rows.

Definition at line 883 of file queries.py.

◆ delete_states_rows()

StatementLambdaElement homeassistant.components.recorder.queries.delete_states_rows ( Iterable[int]  state_ids)
Delete states rows.

Definition at line 543 of file queries.py.

◆ delete_statistics_runs_rows()

StatementLambdaElement homeassistant.components.recorder.queries.delete_statistics_runs_rows ( Iterable[int]  statistics_runs)
Delete statistics_runs rows.

Definition at line 572 of file queries.py.

◆ delete_statistics_short_term_rows()

StatementLambdaElement homeassistant.components.recorder.queries.delete_statistics_short_term_rows ( Iterable[int]  short_term_statistics)
Delete statistics_short_term rows.

Definition at line 583 of file queries.py.

◆ disconnect_states_rows()

StatementLambdaElement homeassistant.components.recorder.queries.disconnect_states_rows ( Iterable[int]  state_ids)
Disconnect states rows.

Definition at line 533 of file queries.py.

◆ find_all_states_metadata_ids()

StatementLambdaElement homeassistant.components.recorder.queries.find_all_states_metadata_ids ( )
Find all metadata_ids and entity_ids.

Definition at line 65 of file queries.py.

◆ find_entity_ids_to_migrate()

StatementLambdaElement homeassistant.components.recorder.queries.find_entity_ids_to_migrate ( int  max_bind_vars)
Find entity_id to migrate.

Definition at line 739 of file queries.py.

◆ find_entity_ids_to_purge()

StatementLambdaElement homeassistant.components.recorder.queries.find_entity_ids_to_purge ( )
Find entity_ids to purge.

Definition at line 857 of file queries.py.

◆ find_event_type_ids()

StatementLambdaElement homeassistant.components.recorder.queries.find_event_type_ids ( Iterable[str]  event_types)
Find an event_type id by event_type.

Definition at line 56 of file queries.py.

◆ find_event_type_to_migrate()

StatementLambdaElement homeassistant.components.recorder.queries.find_event_type_to_migrate ( int  max_bind_vars)
Find events event_type to migrate.

Definition at line 727 of file queries.py.

◆ find_event_types_to_purge()

StatementLambdaElement homeassistant.components.recorder.queries.find_event_types_to_purge ( )
Find event_type_ids to purge.

Definition at line 840 of file queries.py.

◆ find_events_context_ids_to_migrate()

StatementLambdaElement homeassistant.components.recorder.queries.find_events_context_ids_to_migrate ( int  max_bind_vars)
Find events context_ids to migrate.

Definition at line 712 of file queries.py.

◆ find_events_to_purge()

StatementLambdaElement homeassistant.components.recorder.queries.find_events_to_purge ( float  purge_before,
int   max_bind_vars 
)
Find events to purge.

Definition at line 618 of file queries.py.

◆ find_latest_statistics_runs_run_id()

StatementLambdaElement homeassistant.components.recorder.queries.find_latest_statistics_runs_run_id ( )
Find the latest statistics_runs run_id.

Definition at line 672 of file queries.py.

◆ find_legacy_detached_states_and_attributes_to_purge()

StatementLambdaElement homeassistant.components.recorder.queries.find_legacy_detached_states_and_attributes_to_purge ( float  purge_before,
int   max_bind_vars 
)
Find states rows with event_id set but not linked event_id in Events.

Definition at line 691 of file queries.py.

◆ find_legacy_event_state_and_attributes_and_data_ids_to_purge()

StatementLambdaElement homeassistant.components.recorder.queries.find_legacy_event_state_and_attributes_and_data_ids_to_purge ( float  purge_before,
int   max_bind_vars 
)
Find the latest row in the legacy format to purge.

Definition at line 677 of file queries.py.

◆ find_legacy_row()

StatementLambdaElement homeassistant.components.recorder.queries.find_legacy_row ( )
Check if there are still states in the table with an event_id.

Definition at line 707 of file queries.py.

◆ find_oldest_state()

StatementLambdaElement homeassistant.components.recorder.queries.find_oldest_state ( )
Find the last_updated_ts of the oldest state.

Definition at line 640 of file queries.py.

◆ find_short_term_statistics_to_purge()

StatementLambdaElement homeassistant.components.recorder.queries.find_short_term_statistics_to_purge ( datetime  purge_before,
int   max_bind_vars 
)
Find short term statistics to purge.

Definition at line 649 of file queries.py.

◆ find_states_context_ids_to_migrate()

StatementLambdaElement homeassistant.components.recorder.queries.find_states_context_ids_to_migrate ( int  max_bind_vars)
Find events context_ids to migrate.

Definition at line 818 of file queries.py.

◆ find_states_metadata_ids()

StatementLambdaElement homeassistant.components.recorder.queries.find_states_metadata_ids ( Iterable[str]  entity_ids)
Find metadata_ids by entity_ids.

Definition at line 70 of file queries.py.

◆ find_states_to_purge()

StatementLambdaElement homeassistant.components.recorder.queries.find_states_to_purge ( float  purge_before,
int   max_bind_vars 
)
Find states to purge.

Definition at line 629 of file queries.py.

◆ find_statistics_runs_to_purge()

StatementLambdaElement homeassistant.components.recorder.queries.find_statistics_runs_to_purge ( datetime  purge_before,
int   max_bind_vars 
)
Find statistics_runs to purge.

Definition at line 661 of file queries.py.

◆ find_unmigrated_short_term_statistics_rows()

StatementLambdaElement homeassistant.components.recorder.queries.find_unmigrated_short_term_statistics_rows ( int  max_bind_vars)
Find unmigrated short term statistics rows.

Definition at line 892 of file queries.py.

◆ find_unmigrated_statistics_rows()

StatementLambdaElement homeassistant.components.recorder.queries.find_unmigrated_statistics_rows ( int  max_bind_vars)
Find unmigrated statistics rows.

Definition at line 909 of file queries.py.

◆ get_migration_changes()

StatementLambdaElement homeassistant.components.recorder.queries.get_migration_changes ( )
Query the database for previous migration changes.

Definition at line 833 of file queries.py.

◆ get_shared_attributes()

StatementLambdaElement homeassistant.components.recorder.queries.get_shared_attributes ( list[int]  hashes)
Load shared attributes from the database.

Definition at line 38 of file queries.py.

◆ get_shared_event_datas()

StatementLambdaElement homeassistant.components.recorder.queries.get_shared_event_datas ( list[int]  hashes)
Load shared event data from the database.

Definition at line 47 of file queries.py.

◆ has_entity_ids_to_migrate()

StatementLambdaElement homeassistant.components.recorder.queries.has_entity_ids_to_migrate ( )
Check if there are entity_id to migrate.

Definition at line 811 of file queries.py.

◆ has_event_type_to_migrate()

StatementLambdaElement homeassistant.components.recorder.queries.has_event_type_to_migrate ( )
Check if there are event_types to migrate.

Definition at line 804 of file queries.py.

◆ has_events_context_ids_to_migrate()

StatementLambdaElement homeassistant.components.recorder.queries.has_events_context_ids_to_migrate ( )
Check if there are events context ids to migrate.

Definition at line 790 of file queries.py.

◆ has_states_context_ids_to_migrate()

StatementLambdaElement homeassistant.components.recorder.queries.has_states_context_ids_to_migrate ( )
Check if there are states context ids to migrate.

Definition at line 797 of file queries.py.

◆ has_used_states_entity_ids()

StatementLambdaElement homeassistant.components.recorder.queries.has_used_states_entity_ids ( )
Check if there are used entity_ids in the states table.

Definition at line 776 of file queries.py.

◆ has_used_states_event_ids()

StatementLambdaElement homeassistant.components.recorder.queries.has_used_states_event_ids ( )
Check if there are used event_ids in the states table.

Definition at line 783 of file queries.py.

◆ migrate_single_short_term_statistics_row_to_timestamp()

StatementLambdaElement homeassistant.components.recorder.queries.migrate_single_short_term_statistics_row_to_timestamp ( int  statistic_id,
float | None  start_ts,
float | None  created_ts,
float | None  last_reset_ts 
)
Migrate a single short term statistics row to timestamp.

Definition at line 921 of file queries.py.

◆ migrate_single_statistics_row_to_timestamp()

StatementLambdaElement homeassistant.components.recorder.queries.migrate_single_statistics_row_to_timestamp ( int  statistic_id,
float | None  start_ts,
float | None  created_ts,
float | None  last_reset_ts 
)
Migrate a single statistics row to timestamp.

Definition at line 943 of file queries.py.

◆ select_event_type_ids()

Select homeassistant.components.recorder.queries.select_event_type_ids ( tuple[str, ...]  event_types)
Generate a select for event type ids.

This query is intentionally not a lambda statement as it is used inside
other lambda statements.

Definition at line 27 of file queries.py.