pola-rs/polars · error · ValueError
unable to identify string connection as valid ODBC (no…
Error message
unable to identify string connection as valid ODBC (no driver)
What it means
When `read_database` receives a plain string that is not a URI (no "://"), it tries to interpret it as an ODBC connection string, which must contain a "driver=" component. Strings without a driver keyword cannot be identified and raise ValueError.
Solutions
- Include the driver in an ODBC-style string: `"driver={PostgreSQL Unicode};server=...;uid=..."`.
- If it was meant to be a URI, fix the URI (add scheme) and call `read_database_uri`.
- Pass an actual DBAPI connection object instead of a string.
Example fix
// before
pl.read_database("SELECT * FROM t", "DSN=mydb") # raises: no driver=
// after
pl.read_database("SELECT * FROM t", "driver={PostgreSQL Unicode};DSN=mydb")
# or: conn = pyodbc.connect("DSN=mydb"); pl.read_database(q, conn) Defensive patterns
Strategy: validation
Validate before calling
if isinstance(connection, str) and "://" not in connection and "driver=" not in connection.lower():
raise ValueError("string must be a URI (use read_database_uri) or ODBC string containing 'driver=') Type guard
def is_valid_odbc_string(s: str) -> bool:
return isinstance(s, str) and "driver=" in s.lower() Try / catch
try:
df = pl.read_database(q, connection)
except ValueError as e:
if "valid ODBC" in str(e):
conn = pyodbc.connect(f"driver={{PostgreSQL Unicode}};{connection}")
df = pl.read_database(q, conn)
else:
raise Prevention
- Always include driver= in ODBC-style connection strings
- For DSN-based setups, open a pyodbc connection yourself and pass the object
- Validate connection-string shape in config loading, before calling polars
When it happens
Trigger: Calling `read_database(query, "some_string")` where some_string lacks "://" and is not a valid ODBC connection string containing "driver=..." — e.g. a bare DSN name, a database name, or a truncated connection string.
Common situations: Passing a DSN name or database name as a string; mistyping a URI (missing "://"); assuming read_database accepts raw connection strings like a driver's own API.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- cannot infer dtype from
- cannot return a frame before executing a query
- Cannot set `iter_batches` for
- Cannot set `iter_batches` without also setting a non-zero…
- column appears more than once in the query/result cursor
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/9941a717c2211010.
Report an issue: GitHub.
Appendix: source
Thrown at py-polars/src/polars/io/database/functions.py:260
... ) # doctest: +SKIP
""" # noqa: W505
if isinstance(connection, str):
# check for odbc connection string
if re.search(r"\bdriver\s*=\s*{[^}]+?}", connection, re.IGNORECASE):
_ = import_optional(
module_name="arrow_odbc",
err_prefix="use of ODBC connection string requires the",
err_suffix="package",
)
connection = ODBCCursorProxy(connection)
elif "://" in connection:
# otherwise looks like a mistaken call to read_database_uri
msg = "string URI is invalid here; call `read_database_uri` instead"
raise ValueError(msg)
else:
msg = "unable to identify string connection as valid ODBC (no driver)"
raise ValueError(msg)
# adbc_driver_manager must be >= 1.7.0 to support passing Python sequences into
# parameterised queries (via execute_options) without PyArrow installed
if (
execute_options is not None
and not _PYARROW_AVAILABLE
and type(connection).__module__.split(".", 1)[0].startswith("adbc")
):
adbc_version_no_pyarrow_required = "1.7.0"
adbc_driver_manager = import_optional("adbc_driver_manager")
adbc_str_version = getattr(adbc_driver_manager, "__version__", "0.0")
if not parse_version(adbc_str_version) >= parse_version(
adbc_version_no_pyarrow_required
):
msg = (
"pyarrow is required for adbc-driver-manager < "
f"{adbc_version_no_pyarrow_required} when using parameterized queries (via "
f"`execute_options`), found {adbc_str_version}.\nEither upgrade "View on GitHub (pinned to fe841f959e)