API Reference¶
Since npyodbc builds on top of pyodbc, this reference contains only
documentation about features introduced by npyodbc. Consult the pyodbc
wiki for more information about
base pyodbc features.
Cursor
¶
An ODBC cursor for querying a database.
fetchdictarray(size=-1, null_suffix=None, target_dtypes=None)
¶
Fetch a dictionary mapping SQL column names to numpy arrays.
Fetch as many rows as specified by size into a dictionary of NumPy ndarrays (dictarray). The dictionary will contain a key for each column, with its value being a NumPy ndarray holding its value for the fetched rows. Optionally, extra columns will be added to signal nulls on nullable columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
The number of rows to fetch. Use -1 (the default) to fetch all remaining rows. |
-1
|
null_suffix
|
Optional[str]
|
If specified, a new boolean column named |
None
|
target_dtypes
|
Optional[dict[str, DTypeLike]]
|
If provided, this mapping between {column name: dtype} coerces the values read from the database into arrays of the requested dtypes. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, NDArray]
|
A dictionary mapping column names to an ndarray holding its values for the fetched rows. The dictionary will use the column name as key for the ndarray containing values associated to that column. Optionally, null information for nullable columns will be provided by adding additional boolean columns named after the nullable column concatenated to null_suffix |
Notes
Similar to fetchmany(size), but returning a dictionary of NumPy ndarrays for the results instead of a Python list of tuples of objects, reducing memory footprint as well as improving performance. fetchdictarray is overall more efficient that fetchsarray.