Data type mapping¶
When you create a subscription, the Replicator Service proposes a destination column for every source column: name, data type, precision (length) and scale, and nullability. This page explains how it chooses them and what changes the choice. You can always change the proposed columns on the subscription's Columns tab. How some kinds of columns are handled is described on their own pages:
- LOB and long columns
- RRN and ROWID columns, the key added to tables without one
- Spatial, hierarchyid, sql_variant and JSON columns
When to read this¶
- A destination column has an unexpected type, length or nullability.
- Source and destination use different character encodings, and text may not fit.
- You want the same mapping for many subscriptions: set the Subscription Wizard defaults once.
How the default mapping works¶
The Replicator Service maps the columns when a subscription is created, when you click Rebuild Column List, and
when an ALTER adds or changes source columns (see ALTER processing). An ALTER maps only the
columns it added or changed; a changed column keeps its destination type when the new mapping gives the same type, no
larger.
Upgrading to SQDR 7.0 doesn't remap existing subscriptions
SQDR 7.0 maps some columns differently (integers, wide DECIMAL, MySQL types; see below). Existing subscriptions
keep their columns: the new mapping applies only to new subscriptions, Rebuild Column List, and the columns an
ALTER adds or changes. For example, a subscription saved before 7.0 may map a MySQL SMALLINT UNSIGNED to a
signed smallint: if the destination then refuses a row, the error names the column, its value and the type to
widen it to. Change the column's type on the Columns tab.
- It reads the source columns through ODBC: each column's ODBC data type, type name, precision, scale and nullability.
- It reads the destination's types: the types the destination's ODBC driver reports, adjusted by the service's
type configuration (
type-config.json, installed with the service). For a few destinations (such as Kafka, Microsoft Fabric and S3 tables) that configuration provides the whole list. Some types are used only for a source column of exactly the same type name, for example OracleLONG, SQL Servermoneyorsql_variant, SnowflakeVARIANT, PostgreSQLxml. - Integers: an integer column maps to the smallest destination integer type that holds all its values, signed or
unsigned like the source when the destination has both; otherwise to a
DECIMALorNUMERICwith enough digits (a MySQLBIGINT UNSIGNEDbecomesDECIMAL(20)where there's no unsignedBIGINT). Between two databases of the same kind, the source's own type is kept when it's as signed as the source. - Same database, same type: between databases of the same kind, the source's type is kept, with the same precision and scale, when the destination has it.
- Otherwise, the destination's usual type for the same ODBC type, if it's large enough for the column's precision and scale and allows NULL when the column does.
- Otherwise, the smallest type of the same ODBC type that fits, with the source's precision and scale; a type without a length is created at its maximum.
- Otherwise, a related type (see the table below), and as a last resort a character type at its maximum length, which may truncate data.
The mapping puts fidelity first: a value the destination's types can't hold exactly maps to a character type that holds it exactly, rather than to a type that loses digits. If you accept the loss, change the type on the Columns tab.
If no destination type can hold a column, the column is left out of the list: check the Columns tab when the destination is very different from the source.
| Source type | Tried when the destination has no match of the same kind |
|---|---|
Character (CHAR, VARCHAR, long text, and their Unicode versions) |
The other character types, Unicode and non-Unicode, largest last. |
Binary (BINARY, VARBINARY, BLOB) |
The other binary types (bytea for PostgreSQL). |
DATE, TIME, TIMESTAMP |
A CHAR column long enough for the value (10 characters for a date). |
Integers (TINYINT to BIGINT) |
See step 3. |
Boolean (BIT) |
BIT, BOOLEAN or the smallest integer type. |
DECIMAL, NUMERIC |
Each other. A number that no exact numeric type of the destination holds (for example a DECIMAL(38,10) to Db2, whose DECIMAL has at most 31 digits) maps to a VARCHAR (otherwise CHAR) holding the number's text: its digits, sign and decimal point. |
DOUBLE, FLOAT, REAL |
The first floating-point type available, at its maximum precision. |
GUID (uniqueidentifier) |
CHAR(36), otherwise BINARY(16). |
| XML | The destination's XML type, otherwise a character type. |
Subscriptions created by SQDR 6.x or earlier
These subscriptions keep the columns of the earlier mapping (see Upgrading to SQDR 7.0 doesn't remap existing subscriptions):
- Integers were mapped to the destination's type of the same ODBC type, whatever its range or sign, so a
MySQL
SMALLINT UNSIGNEDcan be a signedsmallint, and values above 32767 are stored wrong or refused. When the destination had no match of the same kind, the next larger integer type was tried; forBIGINT,DECIMAL. - A
DECIMALorNUMERICthat no exact numeric type of the destination holds was mapped to a floating-point type, which keeps about 15 significant digits.
Nullability and keys¶
- A destination column allows NULL when the source column does.
- Key columns are created
NOT NULLif forceNonNullPK says so, so that a primary key can be created on destinations that don't allow nullable key columns (SQL Server, MySQL). - Subscriptions that archive all DML activity create every column as nullable.
- Columns added to the destination by an
ALTERare always nullable.
What isn't copied¶
- Default values and identity (auto-increment) attributes of source columns. By default the mapping also
avoids destination types whose values the database generates, such as SQL Server
int identity(suppressAutoUnique). - Constraints and indexes, unless you choose to replicate them on the subscription's Indexes tab or the group's General tab.
Options that change the mapping¶
Each subscription has its own Mapping Options. Their defaults for new subscriptions are on Service Settings › Properties › Subscription Wizard; a few more are advanced service properties.
| Option (service property) | Effect on the mapping |
|---|---|
| Character data destination precision heuristic and Inflation percentage (dbcsPadding, mbcsInflator) | Makes VARCHAR columns (or VARCHAR and CHAR columns) longer than the source's: the precision is increased by the percentage, rounded, by at least 1, and up to the destination type's maximum. Applies only when the destination precision equals the source's and wide-character promotion is off. For PostgreSQL destinations, Unicode character columns are inflated too. |
| Promote CHAR to VARCHAR (promoteToVarchar) | CHAR becomes VARCHAR (and Unicode CHAR becomes Unicode VARCHAR) for lengths above 1. |
| Promote CHAR types to wide-CHAR equivalent types (promoteToWide) | SQL Server and Oracle destinations: character columns become Unicode types (for example NCHAR, NVARCHAR); long text becomes Unicode long text. |
| Default CHAR and VARCHAR as Nullable (createCharAsNullable) | Character columns allow NULL, for destinations such as Oracle that store an empty string as NULL. |
| Map NUMERIC(p,0) to INTEGER types (mapDecimalToInteger) | A DECIMAL/NUMERIC destination without decimals becomes INTEGER up to precision 9 and BIGINT up to 18; larger precisions don't change. Also applies between databases of the same kind. |
| Enable deprecated types (useDeprecatedTypes) | SQL Server destinations: when off (the default), text, ntext, image and datetime aren't used, so text maps to varchar(max) and timestamps to datetime2. |
| Create LOB columns as not logged (createLobAsNotLogged) | Db2 for LUW destinations: CLOB, BLOB and DBCLOB columns are created NOT LOGGED. |
| Quote SQL identifiers, Fold case of identifiers per destination default (quotedIdentifier, foldCase) | Affect column names, not types. |
| useMaxVARCHAR (advanced) | PostgreSQL and Snowflake destinations: VARCHAR columns are created without a length (at the maximum). |
| setOracleSemantics (advanced) | Oracle destinations: character lengths are declared in characters (default), in bytes, or as the database's default. |
| suppressWideTypes (advanced) | Removes Unicode types from the Data Type list of the Columns tab. Doesn't change the proposed types. |
After changing an existing subscription's Mapping Options, click Rebuild Column List to apply them; changes made on the Columns tab are lost (see Columns).
Character data¶
- Different encodings. Text that fits a
VARCHAR(10)in a single-byte source (such as EBCDIC) can need more bytes in a UTF-8 destination. Use inflation, Unicode types, useMaxVARCHAR (PostgreSQL, Snowflake) or character semantics (Oracle) so that it fits. - Moving the data. Character data is moved as Unicode by default (Bind Character Types as Wide (Unicode)), whatever the destination column types.
- During a baseline or snapshot run, the service can strip trailing blanks (rtrimVarchar), cut values at an embedded NUL character (remediateNulls) and replace invalid Unicode characters (remediateData). Values longer than the destination column are cut to fit and reported, whatever these settings (see Truncated values).
- Incremental changes from a
CHARsource to aVARCHARdestination can be padded with blanks like a baseline (padVarchar). - Oracle destinations: during a baseline, an empty string is stored as NULL in a nullable column.
Truncated values¶
Character and binary destination columns (CHAR, VARCHAR, long text, BINARY, VARBINARY, long binary) are cut
when a source value is too long for them.
How you see it: the run ends Successful with warnings, its replication event
has the message Warning: Data replicated with truncation, and the event's details name the columns that were cut.
When the cut lost data you need, widen the destination column (or change the mapping) and run the subscription again.
When a snapshot run or a baseline loads the destination (through ODBC, the MySQL loader or the bulk loader), the Replicator Service checks each character value against its destination column, whatever the Remediate Data and Bind Character Types as Wide (Unicode) settings:
- The value is measured in characters, not bytes: a value that fits in characters is sent whole.
- A longer value is cut at a character boundary to the column's length, so a multi-byte character is never split.
- The warning is given only when the cut loses something other than spaces: trailing spaces cut from a value (for
example a padded
CHARgoing to a shorter column) don't count as truncation.
Dates and times¶
- Fractional seconds are kept up to the destination column's scale; extra digits are truncated and reported as truncation.
- A timestamp replicated to a
DATEcolumn loses its time; to aTIMEcolumn, its date. - Oracle destinations: Oracle has no date-only type, so a source
DATEmaps to the Oracle type the driver reports for timestamps (typicallyDATE) instead of a character column. - SQL Server destinations: with the default mapping, timestamps go to
datetime2(see Enable deprecated types).
Approximate numbers¶
DOUBLE, FLOAT and REAL are approximate types. The Replicator Service maps them to a floating-point type, reads
each value from the source in binary and hands the same value to the destination's ODBC driver, unchanged. Some
drivers still round it, so the last digits can differ at the destination although the mapping is right: such a
difference comes from the driver, not from the mapping. For the SQDR PostgreSQL driver, which rounds these values,
the service sends them as text with enough digits to read back as the same value.
Binary data in a character column¶
A binary source column replicated to a character destination column is copied as its raw bytes, as ODBC defines it;
it isn't converted to hexadecimal text. For the hexadecimal text, convert it at the source, for example with a
derived column whose expression is HEX(MYCOL) (Db2, MySQL).
Per-database notes¶
| Database | Notes |
|---|---|
| SQL Server | varchar(max), nvarchar(max) and varbinary(max) are treated as LOBs. Deprecated types are avoided unless Enable deprecated types is on. Types such as money, smallmoney and sql_variant are used only for source columns of the same type. For sql_variant, geometry, geography and hierarchyid sources, see SQL Server sql_variant and Spatial and hierarchyid columns. |
| Oracle | See Dates and times, Character data and setOracleSemantics. NUMBER is created as DECIMAL with the SQDR and DataDirect Oracle drivers. |
| Db2 (IBM Db2 Connect driver) | GRAPHIC, VARGRAPHIC and DBCLOB are treated as Unicode character types. |
| PostgreSQL | Source character columns are treated as Unicode. Destination char columns are created as bpchar; BLOBs as bytea. Long text (for example from MySQL TEXT types) maps to text. PostGIS geometry and geography: see Spatial and hierarchyid columns. Subscriptions created by SQDR 6.x or earlier: long text was mapped to a varchar that can cut it. |
| MySQL | Date and time columns without a reported precision get a default one. timestamp and datetime destinations have up to 6 fractional digits. Unsigned integers map as described in step 3. The sizes of BIT(n) and TIME(n) source columns are read from the database, so BIT(8) is one byte and TIME(6) keeps its fraction; BIT(n) to MySQL stays bit(n). A nullable TIMESTAMP destination column is created NULL, so a NULL isn't stored as the load time. Subscriptions created by SQDR 6.x or earlier: unsigned integers, BIT(n), TIME(n) and nullable TIMESTAMP columns weren't mapped this way. |
| Snowflake | Timestamps have up to 9 fractional digits. VARIANT, ARRAY and OBJECT are used only for source columns of the same type. |
| Databricks | STRING and BINARY have no length. The destination table is created with CREATE OR REPLACE. |
| BigQuery | NUMERIC and BIGNUMERIC precision depends on the scale. MySQL datetime maps to TIMESTAMP. |
| Kafka | JSON type names: boolean, integer, number (floating-point and decimal), string (character, binary, date and time data), and object and array for source columns of the same type. Subscriptions created by SQDR 6.x or earlier: Db2 types; most columns are character data (CLOB). |
| Microsoft Fabric | Fabric's own type names: BOOLEAN, INT, BIGINT, FLOAT, DOUBLE, DECIMAL (up to 38 digits), STRING and BINARY (no length), DATE, TIMESTAMP. Subscriptions created by SQDR 6.x or earlier: Db2 types. |
| S3 Tables | Iceberg type names: boolean, int, long, float, double, decimal (up to 38 digits), string, binary, date, time, timestamp. Subscriptions created by SQDR 6.x or earlier: Db2 types. |