This documentation describes the integration of MindsDB with TimescaleDB.

Prerequisites

Before proceeding, ensure the following prerequisites are met:

  1. Install MindsDB locally via Docker or Docker Desktop.
  2. To connect TimescaleDB to MindsDB, install the required dependencies following this instruction.

Connection

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.

Usage

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

);

Troubleshooting

Database Connection Error

  • Symptoms: Failure to connect MindsDB with the TimescaleDB database.
  • Checklist:
    1. Make sure the TimescaleDB server is active.
    2. Confirm that host, port, user, schema, and password are correct. Try a direct TimescaleDB connection.
    3. Ensure a stable network between MindsDB and TimescaleDB.

SQL statement cannot be parsed by mindsdb_sql

  • Symptoms: SQL queries failing or not recognizing table names containing spaces or special characters.
  • Checklist:
    1. Ensure table names with spaces or special characters are enclosed in backticks.
    2. Examples:
      • Incorrect: SELECT * FROM integration.travel data
      • Incorrect: SELECT * FROM integration.‘travel data’
      • Correct: SELECT * FROM integration.`travel data`