PostgresqlConfiguration
- class profiles.data_configurations.postgresql_datatable_manager.DataTableMetaData(qau: esdl.esdl.QuantityAndUnitType | None, name: str | None)
- qau: QuantityAndUnitType | None
- name: str | None
- class profiles.data_configurations.postgresql_datatable_manager.PostgresqlDataTableManager(datatable_profile: DataTableProfile)
Implementation of PostgreSQL configuration for DataTableProfile DatabaseConfiguration(type=esdl.DatabaseTypeEnum.POSTGRESQL)
- classmethod get_from_cache_or_create(datatable_profile: DataTableProfile) PostgresqlDataTableManager
- classmethod close_connections()
- datatable_profile: DataTableProfile
- connection: Connection | None
- get_connection()
- disconnect()
- load_data(additional_filters: dict[str, Any] | None = None, column_based: bool = False) tuple[list[list[Any]], list[str], list[DataTableMetaData | None]]
Load data from the configured table using the DataTableProfile settings. Supports querying a single column or all columns. The datetime column is always returned as the first column.
- Parameters:
additional_filters – (key,value) set of additional filters for the query in the WHERE clause
column_based – if True, data is returned by column instead of row
- Returns:
a tuple of profile_values[[]], header[], List[DataTableMetaData] with data loaded from Postgres. the datetime column is always returned as first column
- load_data_custom(schema: str | None, table_name: str, datetime_column_name: str, column_name: str, start_date: datetime | None, end_date: datetime | None, additional_filters: dict[str, Any] | None, multiplier: float | None, downsample_bucket_sec: int | None, column_based: bool) tuple[list[list[Any]], list[str], list[DataTableMetaData | None]]
Execute a flexible SQL query against a PostgreSQL table, supporting a SINGLE value column, datetime filtering, optional downsampling, and additional equality-based filters.
- Parameters:
schema – Optional schema name.
table_name – Name of the table to query.
datetime_column_name – Name of the datetime column.
column_name – Name of the data column to query.
start_date – Optional start datetime for filtering.
end_date – Optional end datetime for filtering.
additional_filters – Optional dict of column=value filters for the WHERE clause.
multiplier – Optional multiplier for scaling profile value.
downsample_bucket_sec – If provided, results are grouped into fixed-size time buckets and averaged.
column_based – If True, return data grouped by column instead of row.
- Returns:
A tuple of (profile_values, header, metadata).
- load_meta_data(column_name: str | None = None) None | DataTableMetaData
Loads metadata from meta_data table
- Returns:
configures
- save_data(profile_values: list[list[Any]], header: list[str], overwrite: bool = True, profile_dict: dict[str, DataTableProfile] | None = None, filter_dict: dict[str, str] | None = None)
Saves data to Postgres. It will insert all the columns in the profile_values by default. If the database doesn’t exist, it will be created automatically on first error.
- Parameters:
profile_values –
header –
overwrite – If True, truncate the existing table rows and insert new ones.
profile_dict – Optional dictionary mapping columnName to DataTableProfile instances for metadata lookup.
filter_dict – Optional dict of filter tag key/value pairs to add as a constant JSONB column to each row.
- Returns:
- save_meta_data(datatable_profile: DataTableProfile, column_name: str | None = None)
Meta data format in schema | table name | column_name | Unit | Quantity | description |
- Parameters:
datatable_profile – the data table profile including unit information and description
column_name – [optional] the column name if not set in the datatable profile (when inserting multiple columns)
- Returns:
None
- exception profiles.data_configurations.postgresql_datatable_manager.InvalidCredentials
Thrown when no credentials are provided for connecting to PostgreSQL.
- exception profiles.data_configurations.postgresql_datatable_manager.InvalidDataTableProfile
Thrown when the DataTableProfile is not complete