Skip to content

Multiple databases

Connect one SQLsaber session to more than one database. The agent picks a database for each step, runs those queries separately, and combines the answers.

Repeat -d or --database. Each value can be a saved connection name, a connection string, or a file path. Mix those forms.

Terminal window
# Two saved connections
saber -d sales -d analytics "Compare last month's revenue to web sessions"
# Mix a saved name with a connection string
saber -d sales -d "postgresql://user:pass@host:5432/events" "..."
# Interactive mode across several databases
saber -d sales -d analytics -d inventory

Single-query mode and interactive mode both work. In interactive mode the footer lists every connected database:

DBs: sales, analytics, inventory | Model: ... | ...

Passing several CSV or Parquet files does not create a multi-database session. SQLsaber loads every file into one in-memory DuckDB database, with one table per file, so you can join across them:

Terminal window
saber -d users.csv -d orders.csv "Join users and orders"
saber -d users.csv -d orders.parquet "Revenue by user"
saber -d users.parquet -d orders.parquet "Join users and orders"

If the repeated targets include another database type or a saved connection, each target resolves on its own into a multi-database session.

When several databases are connected, the agent has to choose which one holds the data. Attach a short description to each connection. Descriptions are shown to the agent, and by the list_dbs tool. They are otherwise optional.

Terminal window
saber db add sales \
--description "Production Postgres: orders, customers, revenue"
saber db add analytics \
--description "ClickHouse warehouse: web sessions, events, funnels"

Add a description to any connection. See Database setup for saber db add.

When more than one database is connected:

  • SQL and knowledge tools require a db_name argument. The agent must choose a connected database for each list_tables, introspect_schema, execute_sql, and knowledge-base call.
  • A list_dbs tool lists every connected database with its name, dialect, and description.
  • Knowledge entries stay scoped per database. Each connection contributes its own context.

In a single-database session none of this is visible. Tool schemas have no db_name argument, and there is no list_dbs tool.

Conversation threads created in a multi-database session record every connected database. When you resume that thread, SQLsaber reconnects to the same set:

Terminal window
saber threads resume a1b2c3d4

Pass a list of targets in SQLSaberOptions. Read names from saber.info.database_names when you need metadata only:

import asyncio
from sqlsaber import SQLSaber, SQLSaberOptions
async def main() -> None:
options = SQLSaberOptions(
database=["sales", "postgresql://user:pass@host:5432/events"],
)
async with SQLSaber(options=options) as saber:
print(saber.info.database_names) # ("sales", "events")
print(saber.db_names) # compatibility property
print(saber.connections) # compatibility property
asyncio.run(main())

See Configuration for the full options list.