ArpeMSSQL — Data types
How SQL Server types map to Apache Arrow on the fetch (read) path, and how Arrow types map back to SQL Server on the ingest/bind (write) path.
The non-obvious cases — TINYINT is unsigned, MONEY is a fixed-scale decimal,
DATETIMEOFFSET collapses to a UTC instant — are called out below.
SQL type name in the field metadata
Since ArpeMSSQL v0.6.7.
Every field the driver returns (query results, ExecuteSchema and
GetTableSchema) carries the column's SQL Server type in the field metadata key
ARPEMSSQL:type, spelled the way SQL Server spells it (the system_type_name
column of sp_describe_first_result_set):
| Column | ARPEMSSQL:type |
|---|---|
INT | int |
DECIMAL(10,2) | decimal(10,2) |
NVARCHAR(50) | nvarchar(50) (the declared length in characters) |
VARCHAR(MAX) | varchar(max) |
VARCHAR(200) with a UTF-8 collation | varchar(200) (since v0.8.0; nvarchar before, see Character & binary) |
TIME | time(7) (the default scale is written out) |
DATETIME2(3) | datetime2(3) |
ROWVERSION | timestamp |
GEOGRAPHY | geography (in every geospatial mode; the GeoArrow keys stay alongside) |
an alias type over VARCHAR(8) | varchar(8) (the base type, as SQL Server reports it) |
SYSNAME | nvarchar(128) |
The Arrow type says how values are represented; this key says what the column is
on the server, so it can be used to recreate the column (varchar(max) and
nvarchar(50) are both Arrow utf8).
Read path: SQL Server → Arrow
Numeric
| SQL Server type | Arrow type | Notes |
|---|---|---|
TINYINT | uint8 | SQL Server TINYINT is unsigned (0–255) |
SMALLINT | int16 | |
INT | int32 | |
BIGINT | int64 | |
BIT | bool | bit-packed on finish |
REAL | float32 | |
FLOAT | float64 | |
DECIMAL / NUMERIC(p,s) | decimal128(p,s) | precision/scale preserved |
MONEY | decimal128(19,4) | fixed scale 4 |
SMALLMONEY | decimal128(10,4) | fixed scale 4 |
Character & binary
| SQL Server type | Arrow type | Notes |
|---|---|---|
CHAR / VARCHAR / VARCHAR(MAX) | utf8 | single-byte code page (CP1252/125x/874/OEM) transcoded via the column collation; columns with a UTF-8 collation (SQL Server 2019+) arrive as UTF-8 and are validated and copied (since v0.8.0, see the note below) |
NCHAR / NVARCHAR / NVARCHAR(MAX) | utf8 | UCS-2 on the wire, decoded to UTF-8 |
TEXT / NTEXT (legacy LOB) | utf8 | TEXT honours its code page; NTEXT is UCS-2 |
BINARY / VARBINARY / VARBINARY(MAX) | binary | |
IMAGE (legacy LOB) | binary | raw bytes |
XML | utf8 | serialized as text |
JSON (SQL Server 2025) | utf8 + arrow.json extension | Since v0.7.6. Field metadata ARROW:extension:name=arrow.json and ARPEMSSQL:type=json (pyarrow shows extension<arrow.json>), in query results, ExecuteSchema, GetTableSchema and GetObjects. The driver offers the native JSON type at login (environment variable ARPEMSSQL_JSON=off stops it); without it the server sends JSON columns as text (plain utf8), as versions before v0.7.6 got them: ARPEMSSQL:type is then varchar(max) since v0.8.0, and nvarchar(max) before or with ARPEMSSQL_UTF8=off. Since v0.8.0 the server sends the JSON type as UTF-8 instead of UTF-16 (see the note below); the values are unchanged. Expressions such as JSON_OBJECT(...) are typed nvarchar(max) by the server itself. |
UNIQUEIDENTIFIER | utf8 | 36-char canonical form; lowercase by default, casing via uuid_casing |
SQL_VARIANT | utf8 | Since v0.7.6. Each value spelled in its base type's form; see sql_variant. |
VECTOR(n) (SQL Server 2025) | fixed_size_list<float32>[n] | Native float32 embeddings, both read and ingest. Requires SQL Server 2025 + the negotiated native-vector transport (auto-on). Without negotiation the server returns the vector as varchar(max) JSON (→ utf8). |
VECTOR(n, float16) (SQL Server 2025 preview) | utf8 | The server sends float16 vectors as JSON text (nvarchar(max)) even with the native-vector transport, so they read as utf8, e.g. '[1.0000000e+000,-2.5000000e+000]'. Ingest is native since v0.7.6 (see below). Needs PREVIEW_FEATURES = ON in the database. |
UTF-8 transport since ArpeMSSQL v0.8.0. The driver offers UTF-8 support at
login, and SQL Server 2019 and later then send char / varchar columns with a
UTF-8 (_UTF8) collation as they are stored. Earlier versions received these
columns converted to UTF-16 by the server, as nvarchar: twice the bytes on the
wire and a conversion on each side (reading UTF-8 collation text is about 2.8
times faster with the new transport). SQL Server 2025 also sends its native
JSON type as UTF-8 on such a connection. Servers before SQL Server 2019 ignore
the offer.
The values read the same. What changes is the ARPEMSSQL:type field metadata of
UTF-8 collation columns, which now says varchar(n) / char(n) /
varchar(max) where it said nvarchar(n) / nvarchar(max). Set the
environment variable ARPEMSSQL_UTF8=off to stop offering UTF-8 support and get
the previous transport and type names.
Temporal
| SQL Server type | Arrow type | Notes |
|---|---|---|
DATE | date32 | days since epoch |
TIME(n) | time32[s|ms] or time64[us|ns] | unit follows the column scale |
SMALLDATETIME | timestamp[s] | |
DATETIME | timestamp[ms] | 1/300 s wire resolution |
DATETIME2(n) | timestamp[s|ms|us|ns] | unit follows the column scale |
DATETIMEOFFSET(n) | timestamp[s|ms|us|ns, tz=UTC] | offset applied → UTC instant |
Temporal scale → unit (for TIME / DATETIME2 / DATETIMEOFFSET):
| Column scale | Arrow unit |
|---|---|
| 0 | seconds |
| 1–3 | milliseconds |
| 4–6 | microseconds |
| 7 | microseconds by default, nanoseconds with timestamp_precision=nanosecond |
SQL Server's scale-7 ceiling is 100 ns, so true Arrow-nanosecond precision is not reachable.
Microsecond default and the timestamp_precision option since ArpeMSSQL v0.6.2.
Earlier versions always emitted scale-7 temporals as nanoseconds.
timestamp_precision)By default a scale-7 DATETIME2 / DATETIMEOFFSET / TIME column is emitted at
microseconds (timestamp[us] / time64[us] → Parquet TIMESTAMP_MICROS),
because many consumers (for example, older Spark) reject
INT64 TIMESTAMP(NANOS). Set the connection option
adbc.arpemssql.timestamp_precision=nanosecond to keep the full 100 ns
resolution (timestamp[ns] / time64[ns]); microsecond (the default) drops
the sub-microsecond digit. Scales 0–6 are unaffected either way.
CLR user-defined types
| SQL Server type | Arrow type | Notes |
|---|---|---|
hierarchyid | binary | opaque server bytes |
geometry / geography | geoarrow.wkb (default) | client-side converted to WKB; see Geospatial types |
sql_variant
Since ArpeMSSQL v0.7.6. Earlier versions failed a query returning a
sql_variant column (including SERVERPROPERTY(...) and system views such as
sys.database_scoped_configurations) with "column N is sql_variant, which this
driver cannot read".
A sql_variant column reads as Arrow utf8 (field metadata
ARPEMSSQL:type=sql_variant). Each value carries its own base type and is
spelled in that type's form:
| Base type | Text |
|---|---|
tinyint / smallint / int / bigint, bit | decimal digits (42, -7, 1) |
real / float | shortest text that reads back to the same value (0.1, 1e+300) |
decimal / numeric | exact, with the value's scale (12.340, -0.5) |
money / smallmoney | exact, 4 decimals (-12.3456, 7.5000) |
date | 2026-10-17 |
time(s) | 13:45:10 plus s fraction digits |
datetime2(s) | 2026-10-17 13:45:10 plus s fraction digits |
datetimeoffset(s) | the local time, then the offset: 2026-10-18 01:30:00 +02:00 |
datetime | 2026-10-17 13:45:10.997 (rounded to the ms as SQL Server shows it) |
smalldatetime | 2026-10-17 13:45:00 |
uniqueidentifier | 36 characters, casing per uuid_casing |
binary / varbinary | 0x then uppercase hex (0x00AB7F) |
char / varchar / nchar / nvarchar | the text, transcoded from the value's own collation |
The base type of a value is not kept: query SQL_VARIANT_PROPERTY(v, 'BaseType') alongside when it matters. For writing, see
sql_variant columns in the write path: a plain Arrow
column gives every row the same base type, a dense union gives each row its
own.
Since ArpeMSSQL v0.8.0 the text of a few real / float values differs from
earlier versions. At some powers of two the text is one digit shorter (2^-44
reads 5.684341886080802e-14, was 5.6843418860808015e-14; both read back to
the same value). Two real values that read as the text of a neighbouring value
are corrected: the real with bits 0x15AE43FE reads 7.0385313e-26, was
7.038531e-26, and so does its negative. real and float values in a
sql_variant also read 10 to 25 times faster.
Not yet mapped
float16— no SQL Server type maps to an Arrowfloat16column or scalar parameter (float16 vectors are covered, see the write path).- Sub-100 ns temporal precision — a SQL Server limit, not a driver gap:
scale-7 columns top out at 100 ns. Nanosecond Arrow output is available via
timestamp_precision=nanosecond(see the scale-7 note above); the default is microseconds.
Geospatial types
Since ArpeMSSQL v0.5.12.
geometry and geography are CLR UDTs whose wire bytes are Microsoft's
proprietary serialization (MS-SSCLRT) — not WKB — so passing them through
unchanged is useless to Arrow / GeoParquet / DuckDB / GeoPandas consumers. By
default the driver converts them to the canonical geoarrow.wkb extension type.
The adbc.arpemssql.geospatial database
option controls the read path:
| Value | Output | Notes |
|---|---|---|
geoarrow (default) | Arrow binary + geoarrow.wkb extension | WKB plus ARROW:extension:name=geoarrow.wkb and an ARROW:extension:metadata JSON object; read directly by GeoPandas / GeoParquet / DuckDB |
wkb | Arrow binary | ISO WKB (x=lon, y=lat), no extension metadata |
varbinary (opt-in) | Arrow binary | raw opaque UDT bytes; backward compatible, not usable outside SQL Server |
How it works. The conversion is client-side. Your query runs verbatim —
nothing is rewritten and there is no extra round-trip. The row decoder recognises
geometry/geography columns from the result's wire metadata and converts each
value's native serialization to ISO WKB as rows stream in. The output is
byte-identical to the server's own STAsBinary() / AsBinaryZM(). NULL
geometries are preserved, and ORDER BY — or any other query shape — keeps the
conversion.
- Z/M coordinates are preserved as ISO WKB Z/M/ZM type codes
(+1000/+2000/+3000), matching
AsBinaryZM(). - Curved geometries (
CircularString/CompoundCurve/CurvePolygon) convert to ISO WKB curve types 8/9/10;geographyFullGlobebecomes SQL Server's nonstandard WKB type 126 — both exactly asSTAsBinary()renders them. Consumer support for curve WKB varies.
In geoarrow mode the extension metadata carries crs as EPSG:<srid> (read
from the first non-NULL value's SRID header; omitted for SRID 4326 / OGC:CRS84 and
for undefined SRIDs, per the GeoParquet convention) and, for geography,
edges: spherical (geometry is planar, so edges is omitted). The reader
decodes rows until every spatial column has an observed SRID — usually just the
first row — then fixes the schema.
Known limitations:
- Mixed SRIDs within one column are not auto-detected; the first observed SRID
is used for the whole column's
crs. - The schema is fixed before rows are delivered, so a spatial column that is NULL
for the whole first batch omits its
crs. Order the query so a non-NULL value appears early, or raiseadbc.arpemssql.batch_size. - Schema-only execution (
Statement.ExecuteSchema) reports spatial columns as plainbinary— it runs underFMTONLY, so no rows and no SRID come back. Bound-parameter SELECTs (WHERE id = ?) are converted normally. - A malformed or unknown-version spatial value fails the read with a clear error
naming the column;
geospatial=varbinaryreads the raw UDT bytes as an escape hatch.
The write/ingest path (Arrow WKB → geometry/geography) shipped in
ArpeMSSQL v0.5.25 — see Write path
below.
Write path: Arrow → SQL Server (ingest & bind)
adbc_ingest loads through INSERT BULK; prepared-statement parameters are
bound through TDS RPC. Arrow arrays are routed to SQL Server types:
- Integers, floats,
bool,decimal,date,time,timestamp(with and without timezone),utf8,binary, and the view types (string_view,binary_view) are accepted on both paths. Dictionary-encoded columns are sent as their values. utf8columns are sent as NVARCHAR (UTF-16), so every character round-trips. For aCHAR/VARCHARtarget with a single-byte code page, bulk ingest converts to the column's code page in the driver, with SQL Server's own best-fit tables, so the stored bytes are what the server would store; UTF-8 collations pass through, and double-byte code pages (932, 936, 949, 950) are sent as NVARCHAR for the server to convert.mode=createmakes string columnsNVARCHAR(4000)and binary columnsVARBINARY(8000); longer values need aMAXcolumn that you create.timestamp[ns]/time64[ns]values are floored to SQL Server's 100 ns tick.XMLtargets are routed viaNVARCHAR(MAX)+ a server-side cast (the raw XML wire type is rejected byINSERT BULK).JSONtargets likewise: anyutf8column (with or without thearrow.jsonextension) loads, and the server refuses a malformed document (error 13609). Since v0.7.6 anarrow.jsoncolumn makesmode=createemit aJSONcolumn (SQL Server 2025+).fixed_size_list<float32>[n]ingests to a SQL Server 2025VECTOR(n)column and, since v0.7.6,fixed_size_list<float16>[n]toVECTOR(n, float16)(native binary;mode=createemitsVECTOR(n)orVECTOR(n, float16)DDL). Other element types are refused. SQL Server does not convert between the two element types: float32 into a float16 column fails with error 42238. Requires the negotiated native-vector transport.- A string column (
utf8,large_utf8,string_view,arrow.json) of JSON arrays, such as'[0.1, -2.5, 3]', loads into an existingVECTOR(n)orVECTOR(n, float16)column at any length: the driver sends it asnvarchar(max)and the server converts each value (a malformed document is error 13609, a wrong number of elements error 42204). The server parses the JSON itself, so this is much slower than afixed_size_list: about 35 times slower for 100,000VECTOR(384)rows. Before v0.7.9 such a value was sent asnvarchar(4000), so any value over 4,000 characters was refused before it reached the server. - Bound
fixed_size_listparameters (since v0.7.6): float32 binds as a nativevector(n)parameter, forINSERTas forVECTOR_DISTANCE; float16 binds as JSON text (nvarchar(max)), because the server refuses a float16 vector parameter, and the server converts it. The server's JSON parser stores-0as0in either type; ingest keeps it. NaN and infinity are refused before any row runs. - A bound
arrow.uuidparameter is sent asuniqueidentifier(since v0.7.10), so it stores the right GUID in auniqueidentifier,sql_variantor string column and matches in aWHERE g = ?comparison. Earlier versions sent it asvarbinary(16): aUNIQUEIDENTIFIERcolumn then stored a different GUID (the first three groups byte-swapped) and a comparison found nothing. AVARBINARY(16)column now receives the GUID's bytes in SQL Server's order, as fromCAST(g AS varbinary), instead of the RFC 4122 bytes; bind a plainfixed_size_binary(16)column to keep the old bytes. - A
sql_varianttarget takes plain Arrow columns and dense unions; see sql_variant columns below. - Arrow WKB →
geometry/geography(since v0.5.25). WKB cells are transcoded client-side to Microsoft's[MS-SSCLRT]UDT format and bulk-loaded withINSERT BULKasvarbinary(max), so a column extracted asgeoarrow.wkbround-trips back in. Point, LineString, Polygon (with interior rings), theMulti*containers,GeometryCollectionand, since v0.7.6, the curvesCircularString,CompoundCurveandCurvePolygonare supported recursively, along with Z/M/ZM ordinates and empty geometries;geographygets the (x, y) → (lat, long) axis-order swap. A geographyFULLGLOBE(WKB type 126) loads too, as a whole value, since v0.7.6. The SRID stamped into each value comes from the column's GeoArrowcrsmetadata, or, when the column has none, fromadbc.arpemssql.ingest.srid, falling back to the kind default (geometry0,geography4326). Malformed WKB (including a compound curve whose pieces do not join, or a circular string with an even number of points) and heterogeneousMulti*children are rejected at encode time with a clear error rather than sent to the server.
Loading WKB into a geometry or geography column works since ArpeMSSQL v0.7.6:
earlier versions failed such a load with "SQL Server error 4816: Invalid column
type from bcp client". Curves and FullGlobe ingest since v0.7.6.
sql_variant columns
A plain Arrow column loaded or bound into a sql_variant column gives every
row the same base type, the one of the column's wire type:
| Arrow type | Base type |
|---|---|
int8, int16 | smallint (SQL Server has no signed tinyint) |
uint8 | tinyint |
int32, uint16 | int |
int64, uint32, uint64 | bigint (uint64 above its range is refused; uint32 / uint64 on bulk ingest only) |
bool | bit |
float32 / float64 | real / float |
decimal | numeric(p,s) from bulk ingest, decimal(p,s) bound |
date32, date64 | date |
time32 / time64 | time(0/3/6/7) |
timestamp | datetime2(0/3/6/7) |
timestamp with a time zone | datetimeoffset(0/3/6/7), offset +00:00 |
utf8, large_utf8, string_view | nvarchar (collation SQL_Latin1_General_CP1_CI_AS) |
binary, fixed_size_binary | varbinary |
arrow.uuid | uniqueidentifier bound, varbinary from bulk ingest of a plain column |
A dense union column gives each row the base type of its member, so one
column can hold an int in one row and a datetimeoffset in the next. The
members map as in the table above; an arrow.uuid member is a
uniqueidentifier and a null member a NULL; a NULL inside a member is NULL
too. mode=create makes the column SQL_VARIANT. Each value is checked before
anything is sent: a string over 4,000 UTF-16 code units or a binary value over
8,000 bytes (the most a sql_variant holds), NaN, infinity, and out-of-range
integers or dates are refused, naming the union row. Not supported: sparse
unions, nested members (lists, structs, unions), members with no SQL Server
type (float16, duration, ...), and dense unions as bound parameters.
import datetime as dt
import pyarrow as pa
ints = pa.array([42], pa.int32())
strs = pa.array(["hello"])
dates = pa.array([dt.date(2026, 10, 31)], pa.date32())
# type ids pick the member of each row, offsets the value inside that member
v = pa.UnionArray.from_dense(
pa.array([0, 1, 2], pa.int8()), pa.array([0, 0, 0], pa.int32()),
[ints, strs, dates])
with conn.cursor() as cur:
cur.adbc_ingest("variants", pa.table({"v": v}), mode="create")
# v is SQL_VARIANT: an int, an nvarchar and a date
Base types with no Arrow member: varchar / char and other collations
(strings are always nvarchar), money, smallmoney, datetime,
smalldatetime. Reading a sql_variant column returns text and drops the base
type, so a table → Arrow → table round trip goes through a union the caller
builds (for example from SQL_VARIANT_PROPERTY(v, 'BaseType')).
Bound string and binary parameters are declared nvarchar(max) /
varbinary(max), so that SQL built from them (? + ?) is not cut at 4,000
characters. A sql_variant cannot hold a MAX type, and SQL Server refuses it
(error 206, or 529 for an explicit CAST, naming sql_variant). The driver
then runs the statement again, once, with nvarchar(4000) / varbinary(8000)
for each string or binary column whose bound values all fit, and keeps those
declarations for the statement's SQL text. It does not retry when another
statement of the batch already ran before the error (a statement compiled late,
for example one using a temp table the batch creates), since that would run it
twice. A longer value cannot go into a sql_variant anyway, and the server's
error stands.
The retry declares every such column bounded, not only the one going into the
sql_variant, so in a statement that also concatenates parameters (? + ?)
the result is cut at 4,000 characters. Bind the sql_variant value in a
statement of its own when that matters. The environment variable
ARPEMSSQL_BIND_BOUNDED_STRINGS=0 turns the retry off.
Dense union ingest into sql_variant since ArpeMSSQL v0.7.10. Bound string,
binary and arrow.uuid parameters work into a sql_variant column since
v0.7.10: earlier versions failed such an INSERT, UPDATE or CAST with SQL
Server error 206 or 529.
Bind inputs with no SQL Server equivalent return NOT_IMPLEMENTED: float16
scalars and null-typed parameters.
See also
- Connection → Type rendering — the
uuid_casing,geospatialandtimestamp_precisionoptions - Compatibility — validated SQL Server versions and ADBC conformance results
- Examples — reading and ingesting typed data