docs/integrations/data-integrations/timescaledb.mdx
This documentation describes the integration of MindsDB with TimescaleDB.
Before proceeding, ensure the following prerequisites are met:
Establish a connection to TimescaleDB from MindsDB by executing the following SQL command and providing its handler name as an engine.
CREATE DATABASE timescaledb_datasource
WITH
engine = 'timescaledb',
parameters = {
"host": "examplehost.timescaledb.com",
"port": 5432,
"user": "example_user",
"password": "my_password",
"database": "tsdb"
};
Required connection parameters include the following:
user: The username for the TimescaleDB database.password: The password for the TimescaleDB database.host: The hostname, IP address, or URL of the TimescaleDB server.port: The port number for connecting to the TimescaleDB server.database: The name of the TimescaleDB database to connect to.Optional connection parameters include the following:
schema: The database schema to use. Default is public.Before attempting to connect to a TimescaleDB server using MindsDB, ensure that it accepts incoming connections using this guide.
The following usage examples utilize the connection to TimescaleDB made via the CREATE DATABASE statement and named timescaledb_datasource.
Retrieve data from a specified table by providing the integration and table name.
You can use this established connection to query your table as follows,
SELECT *
FROM timescaledb_datasource.sensor;
Run PostgreSQL-native queries directly on the connected TimescaleDB database:
SELECT * FROM timescaledb_datasource (
--Native Query Goes Here
SELECT
model,
COUNT(*) OVER (PARTITION BY model, year) AS units_to_sell,
ROUND((CAST(tax AS decimal) / price), 3) AS tax_div_price
FROM used_car_price
);