Skip to content

Sources

ODBC

Load tables and query results from any database with an ODBC driver: connections, choosing tables, query tables, value sizes, memory and types.

An odbc source loads tables, views and query results from any database that has an ODBC driver. SQLLoad reads the rows as Arrow through the driver and loads them into the source’s target.

[connections.erp]
kind = "odbc"
connection_string = "${ENV:ERP_ODBC}"
[sources.erp]
kind = "odbc"
connection = "erp"
description = "Tables of the ERP database."
include = ["sales.*"]
exclude = ["sales.tmp_*"]
write_strategy = "replace"
[sources.erp.tables."sales.items"]
description = "Items, one row per item."
cursor_column = "updated_at"
unique_key = ["id"]
write_strategy = "merge"
[sources.erp.tables.recent]
description = "Items added recently."
sql = "SELECT id, name FROM sales.items WHERE id > 2400"
$ sqlload plan -v
…
Loads (2) sqlload load
├── raw.erp__items merge (unique_key: id)
│ ├── source odbc erp sales.items
│ ├── route read as Arrow -> DuckDB takes Arrow
│ ├── reads updated_at: first run, everything
│ └── commits once, at the end of the read (updated_at isn't read in order)
└── raw.erp__recent replace
├── source odbc erp query recent
└── route read as Arrow -> DuckDB takes Arrow
…

The sqlload and sqlload-cli wheels include ODBC on every platform. A build from source needs the odbc feature (cargo install sqlload --features odbc); without it, plan refuses an odbc source.

Key Meaning
connection_string The driver’s connection string, such as Driver={PostgreSQL Unicode};Server=db.example.com;Database=erp;Uid=loader;Pwd=.... Use ${ENV:NAME}, since it usually holds a password.
dsn A data source name from odbc.ini, instead of connection_string. It and user can’t contain ;, { or }.
user, password With dsn, when the DSN doesn’t hold them.

Set connection_string or dsn, not both. Install the database’s ODBC driver where SQLLoad runs. SQLLoad reaches it through a driver manager:

  • Windows: the one built into Windows. Register drivers and DSNs as usual (ODBC Data Sources).
  • Linux and macOS wheels: a bundled unixODBC 2.3.14. It reads odbcinst.ini and odbc.ini from /etc on Linux, Homebrew’s etc on macOS, or the folder ODBCSYSINI names, and user DSNs from ~/.odbc.ini. A driver registered by file name alone (Driver=psqlodbcw.so, as Debian and Ubuntu do) is looked for in /usr/lib/<arch>-linux-gnu/odbc, /usr/lib/<arch>-linux-gnu, /usr/lib64/odbc and /usr/lib64, or Homebrew’s lib.
  • cargo install --features odbc: the system’s unixODBC (unixodbc-dev on Debian and Ubuntu, unixodbc with Homebrew).

SQLLoad quotes names in ANSI double quotes ("sales"."items"). A database that doesn’t read them as names is refused when the source is read; switch it to ANSI quoting. For MySQL, add INITSTMT=SET SESSION sql_mode=CONCAT(@@SESSION.sql_mode,',ANSI_QUOTES'); to the connection string.

Driver Tested
psqlODBC (PostgreSQL Unicode) Against Postgres 17, on Linux and Windows. Add BoolsAsChar=0 to the connection string so boolean columns load as bool, not text.
Microsoft ODBC Driver 18 for SQL Server Against SQL Server 2022 on Linux and LocalDB on Windows, datetime2 and legacy datetime cursors included.
MySQL Connector/ODBC (MySQL ODBC Unicode Driver) Against MySQL 8.4 with ANSI_QUOTES, on Ubuntu 24.04, Debian 13 and Windows. On Linux, install MySQL’s package for your distribution, not the generic glibc tarball, whose OpenSSL fails to load once another driver has loaded the system one. See MySQL Connector/ODBC on Linux.
MariaDB Connector/ODBC 3.1 Against MySQL 8.4 by hand. It reports no primary keys there; see MariaDB Connector/ODBC 3.1.
OpenEdge (Progress) Timestamp handling only, not against a live server. plan checks the driver takes the cursor’s bounds; see Cursor bounds.
Others Untested. A driver must describe prepared statements and list tables; run sqlload plan to see the types it reports.

MySQL’s Debian and Ubuntu packages of Connector/ODBC 9.7 and 26.10 can’t load in a Python process that has already used libstdc++, such as one running the sqlload package. unixODBC then reports the driver missing, and SQLLoad adds what to check under the message:

[unixODBC][Driver Manager]Can't open lib '/usr/lib/x86_64-linux-gnu/odbc/libmyodbc9w.so' : file not found
  • The sqlload package’s sqlload command restarts itself once with libstdc++ in LD_PRELOAD, so the driver loads with nothing set. Processes it starts inherit the preload; SQLLOAD_NO_PRELOAD=1 turns it off. The sqlload-cli package’s sqlload needs no preload.

  • A Python program that imports SQLLoad and loads in its own process needs the preload from its start, as does pyodbc in such a process:

    LD_PRELOAD=libstdc++.so.6 python load.py

MySQL’s Debian 13 package of 9.7 also registers its drivers under /usr/lib//odbc/, where they aren’t, so every driver manager reports file not found. Fix the registration:

sudo sed -i 's#/usr/lib//odbc/#/usr/lib/x86_64-linux-gnu/odbc/#' /etc/odbcinst.ini

MariaDB Connector/ODBC 3.1 (Debian 13’s odbc-mariadb, 3.1.15) reports no primary key for MySQL 8.4 tables. A table with unique_key = "{primary_key}" fails plan, and the error names the key INFORMATION_SCHEMA lists:

$ sqlload plan
…
└── raw.erp__items no key to merge on
├── reason items (kind = "odbc"): unique_key = "{primary_key}", but the source reports no
│ primary key for the table. The ODBC driver reported no primary key, but the
│ database's INFORMATION_SCHEMA lists PRIMARY KEY (id), so the driver's key lookup is
│ wrong (MariaDB Connector/ODBC 3.1 finds none in MySQL 8.4)
└── fix name the key columns, such as unique_key = ["id"]
…

Name the key columns on each such table, or use MySQL Connector/ODBC.

Cursor bounds bind as parameters of the cursor’s type ("updated_at" > ?), so a millisecond maximum such as 23:59:59.997 resumes exactly. A numeric cursor compares with a bare number ("id" > 41). A cursor pinned in columns, or of another type such as a timestamp with a time zone, compares with a quoted literal the database converts; check that yours does.

A timestamp bound carries its column’s fractional digits (three or six) when it has no more, else every digit, never rounded. On SQL Server, timestamps bind as datetime2(7); against a legacy datetime, as ISO 8601 text in the column’s precision. For a timestamp or date cursor, --start-cursor, --end-cursor and cursor_start also take ODBC escapes, such as {ts '2026-01-31 23:59:59.997'} or {d '2026-01-31'}.

For a driver that refuses bound values, as OpenEdge’s may, cursor_bounds = "literals" on the source or a table entry writes every bound into the query as an ODBC escape. The default is "parameters".

[sources.erp]
kind = "odbc"
connection = "erp"
cursor_bounds = "literals"
Cursor Bound
Timestamp without a time zone {ts '2026-01-31 23:59:59.997'}, with the column’s fractional digits when the bound has no more, else the fewest of 0, 3, 6 or 9 that keep every digit
Date {d '2026-01-31'}
Number 41
Text 'o''brien', each quote doubled

Keep the default on SQL Server, whose {ts} escape rounds milliseconds to 1/300 s. A text bound holding a backslash is refused under literals, since some databases (MySQL by default) read it as an escape; set cursor_bounds = "parameters", or start past it with --start-cursor.

plan runs each table with a text, date or timestamp cursor once with bounds that select no rows. When the driver refuses the bounds one way but takes them the other, the table fails, naming the setting:

Errors (1)
└── items
└── reason the ODBC driver refuses the cursor updated_at's bounds as parameters ([HY000] …) but takes them as ODBC escapes; set cursor_bounds = "literals" on source erp or its table entry

When both ways fail, the error shows both of the driver’s errors.

include and exclude are schema.table patterns (* matches any text), matched without regard to case against the tables and views the driver reports; in a database without schemas, against the table name. A [sources.erp.tables."schema.table"] entry sets options for one table but doesn’t add it. A source needs an include pattern or a query table.

Every table needs a write_strategy, and a merge table a unique_key: its columns, or "{primary_key}" for the key the driver reports (see Write strategies). A query table reports no key.

SQLLoad asks the driver only for what include names, one lookup per pattern, with * as % and ? as _:

include Schema and table the driver is asked for
PUB.action PUB, action
PUB.* PUB, %
sales.tmp_? sales, tmp__
events (a database without schemas) any schema, events

SQLLoad lists every table instead, once per source, when:

  • a pattern holds [, { or \, more than one ., or a * or ? without a .;
  • a lookup finds nothing, often because the driver compares names case-sensitively (psqlODBC, and the MySQL and MariaDB drivers on Linux), so ERP.Items finds nothing for erp.items.

The result is the same either way, but on a large catalog the full listing is slow: write names in the catalog’s case. RUST_LOG=info logs each full listing and why. On such a driver, a lookup that finds a table doesn’t also find one differing only in case, such as erp.Items beside erp.items: name each in include.

SQLLoad reads a table’s primary key only for a merge table, a table without a write_strategy (whose error suggests one), and a table loading into ClickHouse.

A table entry with sql is a query table, named by its key. plan prepares the query to read its columns, without running it. Write it in the database’s own SQL. cursor_column names a column of its result: SQLLoad filters outside the query, so it needs no placeholder.

where keeps the rows that match a condition in the database’s own SQL:

[sources.erp]
where = "site = 'BE01'"
[sources.erp.tables."sales.orders"]
where = "status <> 'X' AND site = 'BE01'"

It’s ANDed into every read of the table, including --reload and the key scan of load --sync-deletes, and the table keeps its primary key. A table’s where replaces the source’s. plan shows it on a filter line and checks it on the source, so a typo fails plan. A query table refuses where: put the condition in its sql.

A row that stops matching stays in a merge, append or delete_insert table, but isn’t updated. replace drops it, as does deletes with load --sync-deletes (see Rows deleted at the source).

A text or binary column is a long column when its buffer, from the length the driver reports, would be over long_column_threshold (4 KiB), or the driver gives no length, as for TEXT, LONGTEXT or VARCHAR(MAX). A table with a long column is read value by value, each value at its own size and never cut. Other tables are read in bulk. See Memory.

max_text_size and max_binary_size (bytes, UTF-8 for text) optionally cap every text or binary column. A capped column is long only when its cap is over the threshold. A value over its cap fails the read, naming the setting to raise; it’s never cut short.

Each ODBC table has a fetch buffer, the most the rows of one fetch hold:

Key Default Meaning
max_batch_memory 512 MiB, or a quarter of each table’s share of the memory budget when less The fetch buffer of each table, such as "2GB" or "256MiB". Set, it’s used as it is.
long_column_threshold "4KiB" The buffer per value over which a text or binary column is read value by value.

The fetch buffer changes how many fetches a read takes, not commits or data, and bounds fetches only, not the load’s memory. To measure that, read peak_memory_bytes in the JSON report, or run once with --memory-per-table on Linux; see Finding a source that uses too much memory.

plan -v shows how each table fetches:

$ sqlload plan -v --memory-limit 2GiB
…
├── raw.shop__contacts replace
│ ├── fetch up to 87.9 MiB or 65,536 rows per fetch; 1 long column (notes), so all 3 columns are read value by value
│ └── buffer 87.9 MiB fetch buffer per table (capped: a quarter of each table's 352 MiB share of the memory budget)
└── raw.shop__orders replace
├── fetch ~14.5 MiB per fetch, 65,536 rows
└── buffer 87.9 MiB fetch buffer per table (capped: a quarter of each table's 352 MiB share of the memory budget)

A fetch holds at most 65,536 rows. Value by value (contacts), it also ends once its values fill the fetch buffer; a larger value still loads, ends its fetch, and logs a warning. Reading value by value is slower but saves memory when values are much shorter than their column allows. To read a table in bulk, raise long_column_threshold above its long column’s size.

When a fetch may hold more than a quarter of a table’s share, as a larger max_batch_memory may, plan warns, and load checks again when it starts:

$ sqlload plan --memory-limit 2GiB --concurrency 2
…
Warnings (1)
└── an ODBC fetch may hold 954 MiB, more than the 176 MiB a fetch gets of each table's 703 MiB share of the memory budget; lower max_batch_memory on source shop, or raise memory_limit

SQLLoad reads each column’s type as the driver describes it:

ODBC type Loads as
TINYINT, SMALLINT smallint
INTEGER, BIGINT int
NUMERIC(p,s), DECIMAL(p,s), p up to 38 decimal(p,s), read as text so no digit is lost
REAL, FLOAT, DOUBLE float
BIT bool
DATE, TIME date, time
TIMESTAMP timestamp_ntz, read in at least microseconds; a timestamp with a time zone, in the session’s time zone
CHAR, VARCHAR and their wide and long forms text
BINARY, VARBINARY, LONGVARBINARY binary
Anything else, and NUMERIC above 38 digits text, as the driver writes it

A decimal value with more places than its column’s scale fails the read rather than being rounded. psqlODBC describes an unbounded numeric as NUMERIC(28,6), so pin such a column, such as columns = { amount = "decimal(38,10)" } or "text". A value that doesn’t convert to a pinned type fails the read, naming the column. See Types.

The database user needs to read the catalog (tables and keys) and SELECT on the tables and views. An error names a key the driver missed only when INFORMATION_SCHEMA shows it to the user: Postgres, for one, shows a table’s constraints only to its owner or a user with a privilege on it other than SELECT.