Common Relational Database Rules
MySQL, Oracle, PostgreSQL, and SQL Server follow common rules when reading by time window. Check each rule when configuring a task. Date placeholder granularity is a common source of errors; a successful preview or automatic table creation does not mean all values have passed verification.
Entry point: taosExplorer → Data In → the corresponding relational database. Run source queries in that database's client, and verify the target in taosExplorer's Data Browser or the taos CLI.
This section describes the common rules for reading MySQL, Oracle, PostgreSQL, and SQL Server by time window. Tasks read records using an SQL template, then map them to TDengine. Continuous queries are not a general-purpose CDC subscription to source transaction logs. Do not assume they capture all historical updates, deletions, or new rows without time markers.
1. Read Windows
Select the time column used for filtering, confirm its type and time zone, and determine whether it represents business collection time or ingestion time. Use paired start/end placeholders in the template, with a start-inclusive, end-exclusive window:
SELECT ts, device, temperature
FROM readings
WHERE ts >= ${start} AND ts < ${end}
ORDER BY ts;
This is an SQL template for the task configuration, not a statement to run in the taos CLI. The source table, fields, and time type must exist. Each database uses different expressions to replace time placeholders; do not add quotation marks manually. For source-side verification, replace the placeholders with explicit time expressions recognized by the source database.
For the first run, set a one-minute window or another small range known to contain data, and specify an end time. Select committed, queryable data within retention, and record the source count and representative records in the same window. The target primary-key time can differ from the filtering cursor, but preserve both meanings. Do not lose business time merely to track ingestion time.
1.1 Time Placeholders
Use the following placeholders in pairs. Their replacements already include the quotation marks or date functions required by the database. Do not write '${start}', or mix ${start} with ${end_no_tz}.
| Placeholder pair | MySQL | Oracle | PostgreSQL | SQL Server |
|---|---|---|---|---|
${start} / ${end} | STR_TO_DATE datetime expression | TO_DATE datetime expression | Datetime literal with time zone offset | Datetime literal with time zone offset |
${start_no_tz} / ${end_no_tz} | Same as the preceding pair | Same as the preceding pair | Datetime literal without a time zone | Datetime literal without a time zone |
${start_date} / ${end_date} | Date expression | Date expression, at midnight on that date | Date literal | Date literal |
${start_time} / ${end_time} | Time-only expression | Time-only literal | Time literal with offset | Time literal with offset |
For a window starting at 2024-03-14T00:00:00Z with task time zone +08:00, placeholders use the local time 2024-03-14 08:00:00 in that zone, to second precision. MySQL expands ${start} to STR_TO_DATE('2024-03-14 08:00:00','%Y-%m-%d %H:%i:%s'), and Oracle to TO_DATE('2024-03-14 08:00:00','YYYY-MM-DD HH24:MI:SS'); both produce the same result for ${start_no_tz}. PostgreSQL and SQL Server expand ${start} to '2024-03-14 08:00:00+08:00' and ${start_no_tz} to '2024-03-14 08:00:00'. The absence of an offset in MySQL and Oracle expressions does not make the selected time UTC.
In the same example, ${start_date} becomes STR_TO_DATE('2024-03-14','%Y-%m-%d') in MySQL, TO_DATE('2024-03-14','YYYY-MM-DD') in Oracle, and '2024-03-14' in PostgreSQL and SQL Server. End placeholders follow the same rules.
Date placeholders do not retain hours, minutes, or seconds. Two boundaries on the same day become the same date, producing an empty window. The end date is midnight at the start of that day, so < ${end_date} excludes the entire end date. Use these placeholders only when reading whole dates, and check windows that cross midnight. The datetime templates above expand to second precision; they do not demonstrate precise reads at subsecond boundaries.
Time-only placeholders have no date. Use them only in queries where the source table or other conditions already establish the date, not as replacements for full datetime conditions across arbitrary days. When the window ends at midnight or crosses a day boundary, ${end_time} uses the 24:00:00 form in MySQL, Oracle, and PostgreSQL, while SQL Server uses 23:59:59.9999999. PostgreSQL and SQL Server also retain the task offset. Verify boundaries at the source using the actual type and comparison operator. In particular, SQL Server's < excludes that final time point; do not assume every precision point of the day is covered. For ordinary migrations, prefer a full datetime placeholder pair matching the column type.
1.2 Time and Time Zone
Start and end times are absolute instants with UTC offsets; the task time zone does not change those instants. Task parameter time_zone has no separate field in taosExplorer. If unset, it uses the start time's UTC offset: the page time zone offset in effect when the start was set. Editing an existing task without changing the start preserves both time bounds and the task time zone. For sources storing UTC, switch the page to UTC before setting the start, or set time_zone=UTC through the API or CLI.
time_zone accepts fixed UTC offsets such as +08:00 or +0800, or UTC or Z, but not IANA names such as Asia/Shanghai. Invalid values fail when starting a task or previewing data. The offset stays fixed throughout the task and does not follow daylight saving time. It determines local SQL time-placeholder values and query-window date boundaries, rather than using the taosX host time zone.
| Source database | Session time zone and fixed-offset range (inclusive) |
|---|---|
| MySQL | taosX sets session time_zone to the task time zone. MySQL 8.0.19 and later accept -13:59 through +14:00; earlier versions accept -12:59 through +13:00. taosX checks the former; older servers still require their narrower range. |
| Oracle | taosX runs ALTER SESSION SET TIME_ZONE with the task time zone. Oracle's documented range is -12:00 through +14:00. |
| PostgreSQL | Uses the connection's default session time zone. The task offset range is -15:59 through +15:59 when the template includes a complete ${start}/${end} or ${start_time}/${end_time} pair. |
| SQL Server | The task time zone does not automatically set the source session time zone. The task offset range is -14:00 through +14:00 when the template includes either complete pair above. |
For PostgreSQL and SQL Server, either complete pair triggers database-specific validation even if the template also uses placeholders without offsets. If neither complete pair exists, fixed offsets from -23:59 through +23:59 are accepted for local time conversion.
Check query-placeholder behavior separately from time handling of values read from the source:
- MySQL
TIMESTAMPand OracleTIMESTAMP WITH LOCAL TIME ZONEuse the session time zone, which is the task time zone. MySQL comparesTIMESTAMPagainst the template as absolute instants, andDATETIMEas wall-clock time in the task time zone. - MySQL
DATETIME, OracleDATE/TIMESTAMP, and PostgreSQLtimestampare read as wall-clock values without task time zone conversion. SQL Serverdatetime,datetime2, andsmalldatetimeare read as UTC. - Oracle
TIMESTAMP WITH TIME ZONE, PostgreSQLtimestamptz, and SQL Serverdatetimeoffsetare converted using the offset in the value, independently of the task time zone. - For PostgreSQL, use
${start}/${end}withtimestamp with time zone. Use${start_no_tz}/${end_no_tz}only fortimestamp without time zonecolumns storing wall-clock time in the task time zone.
Target time precision must be at least the source precision. Lower precision truncates fractional seconds, potentially merging distinct times into the same primary key and overwriting values. Compare timestamps and unique primary-key counts during verification.
2. Query Interval and Delay
Query Interval defaults to 1 day and only divides the read range; it does not schedule continuous queries. Each window is at most one interval long and never crosses midnight in the task time zone. Intervals longer than 1 day behave as 1 day, and first or last windows can be shorter.
Delay sets the safe watermark: current time minus delay. In continuous synchronization mode, if the end is absent or in the future, taosX first reads history up to that watermark, then checks about once per second. When the range from the last checkpoint to the watermark exceeds the minimum real-time window, it reads that range, split by Query Interval. MySQL and PostgreSQL default live_sync_min_window to 10 seconds; Oracle and SQL Server use a fixed 10 seconds. With a 60-second delay, a query run at 09:01 reads only data before 09:00; this does not imply an hourly trigger.
Delay allows time for source commits and late arrivals, but cannot recover older-time records after the checkpoint has passed. Confirm maximum source lateness and a reliable cursor before assessing a lookback strategy. Oracle scheduled mode uses the same current-time-minus-delay watermark, while the schedule controls triggers. See Oracle.
3. Target Modeling and Table Partitioning
One source table can map to one TDengine supertable and multiple child tables. Define the device field, time column, value columns, and tags before checking the preview. To query devices separately, pair Subtable Fields with the corresponding conditions in the SQL template. Filling in subtable fields alone does not automatically rewrite arbitrary SQL.
For example, in source table readings, suppose device is a non-null device identifier. Enter a query in Subtable Fields, not just a column name:
SELECT DISTINCT device FROM readings;
Enter the following in SQL Template:
SELECT ts, device, temperature FROM readings
WHERE ts >= ${start} AND ts < ${end} AND ${device}
ORDER BY ts;
${device} expands to a complete equality condition, such as device='d001', not just d001. Do not write device=${device} or add quotation marks. For multiple device identifier fields, return them together in the DISTINCT query and reference each with AND ${字段名} in the template. Also map device fields to target child table names or tags. Source grouping queries and target table creation are separate steps.
Start by verifying simple, non-null string or integer identifiers. If identifiers contain quotation marks, special characters, nulls, or complex data types, check the expanded statements and samples before expanding to the whole database. DISTINCT queries also require permissions and can load the source. Ask the source administrator to confirm indexes and acceptable scope.
Do not enable complex splitting, filtering, or high concurrency all at once in the first trial migration. Sorting helps process data by time, but does not replace checks for window completeness and source consistency.
3.1 Wide and Narrow Table Mapping
| Source table shape | Typical columns | Target model |
|---|---|---|
| Wide device table | ts, device, voltage, current | One child table per device; voltage and current are regular columns, and the device identifier is a tag. |
| Narrow measurement-point table | ts, point, value, quality | One child table per measurement point; value and quality are regular columns, and the point identifier is a tag. |
| Separate business and ingestion times | reading_ts, ingest_ts, device, value | Filter windows using a reliable ingest_ts, and map reading_ts to the target primary-key time. Store ingestion time separately for auditing if necessary. |
After retrieving samples, check the recognized types, select the target supertable, child table template, column and tag mappings, then click Preview. Do not use SQL functions such as CONCAT directly as mapping expressions. For mapping, extraction, and transformation syntax, see Target Table Modeling and Field Mapping and Extraction, Splitting, Filtering, and Transformation.
3.2 Type Checks
| Category | Required checks | Suggested verification samples |
|---|---|---|
| Integers | Signed/unsigned, minimum and maximum values, target range | Boundary values, 0, NULL. |
| Fixed-point and floating-point | Source precision/scale, preview type, target column type | High-precision decimals, negative numbers, and values not exactly representable in binary floating-point. Do not assume all source DECIMAL values are preserved without loss. |
| Datetime | Whether the type includes a time zone, target database precision, multiple rows for the same device and time | Day boundaries, non-whole-hour offsets, subsecond values, and window boundaries. |
| Strings and binary | Source connection character set, target type, length units and limits | Chinese text, empty strings, NULL, long values, and non-text binary data. |
| JSON and special types | Actual preview values and extraction method | Arrays/nested objects; explicitly convert spatial and custom types in source SQL before testing reads. |
For type errors, see Write Errors and Invalid Data. Successful automatic table creation or a preview does not mean all values fit the target range. Check error archives and policies before expanding the time range. Relational queries also do not guarantee that all windows come from one cross-window transactional snapshot, and read tasks can increase source database load.
3.3 Fixed-Point and Date Read Representations and Target Types
Check the source database type, sample representation, and target column type separately. Exact decimals read as strings can still be explicitly mapped to a confirmed supported DECIMAL(p,s). A string representation neither restricts storage to text nor guarantees that the correct target precision has already been selected automatically.
| Source | Exact numeric read representation | Key datetime checks |
|---|---|---|
| MySQL | DECIMAL is read as a decimal string. | DATE, TIME, and DATETIME are read as strings; TIMESTAMP follows the timestamp path. DATETIME is read as a wall-clock value without task time zone conversion; define the source convention separately when mapping it to a timestamp. |
| Oracle | NUMBER and FLOAT are read as strings; BINARY_FLOAT and BINARY_DOUBLE are floating-point. | DATE includes both date and time, unlike date-only types in other databases. Check TIMESTAMP, time-zone-aware types, and local-time-zone types separately. |
| PostgreSQL | NUMERIC is read as a decimal string. | DATE, TIME, and TIMESTAMP without a time zone are read as strings; TIMESTAMPTZ is handled as an instant, and the target display does not preserve the original input offset notation. |
| SQL Server | DECIMAL and NUMERIC are read as strings; check the suggested precision and scale when metadata is available. | Distinguish date, time, datetime2, and datetimeoffset; timestamp/rowversion is a binary version number, not business time. |
For exact values such as monetary amounts or cumulative quantities, proceed in this order:
- Select high-precision positive values, values at the smallest decimal unit, negative values, zero, and genuine
NULLat the source. Preserve source character output and pass samples as quoted decimal strings to avoid conversion to floating-point by spreadsheets or general JSON number parsing. - Retain the original fields after retrieving samples. Select the target column and explicitly set
DECIMAL(p,s), wherepcovers the total integer and fractional digits andscovers the required business scale. After previewing, runDESCRIBEto check the actual type. Do not introduceDOUBLEor floating-point mathematical expressions during conversion. - If the fixed-point path is not yet confirmed, first map to an
NCHARexact-text column with sufficient capacity, and compare the same source samples character by character. Text storage changes sorting, aggregation, and comparison semantics; subsequent numeric calculations need a separate design. - Test values exceeding target precision, values with excessive fractional digits, and invalid characters separately. Record rejection, rounding, nulls, or other handling based on actual previews, logs, and error policies. If the business does not allow changes, adjust the target model or source query and verify again. Do not mix these rows into normal samples.
- Compare target values and nulls individually, not just the decimal places displayed on the page. Distinguish genuine
NULL, the string"NULL", an empty string, and zero. Do not set a default zero that masks missing exact values.
Before writing date fields or time fields without a time zone to the primary timestamp, define the date, time zone, format, and target database precision. A date-only DATE can be stored as agreed text; a time-only TIME cannot identify a day on its own. After converting a time without a time zone, also check a known UTC instant. Do not mechanically append Z to a string and change its business meaning. For a complete exact-value exercise, see MySQL Exact Decimal and Date Example.
3.4 Retrieve Samples and Complete Mapping
The minimal temperature examples on the database-specific pages above all use ts, device, and temperature. Configure them with the following steps, retaining the target database and SQL window from the current database-specific page.
Expand Data Mapping and complete this page's temperature example in the following order. Confirm that this page's target database is selected first; otherwise the supertable list is unavailable.
- Click Retrieve from Server to obtain samples from this page's source table and query window. Check the sample limit and request timeout. A few samples are only for configuration, not evidence that the complete window is synchronized.
- Under Recognized Columns, confirm
ts,device, andtemperature. If source columns use uppercase or other names, follow SQL aliases and actual results. Check datetime types, non-null devices, and numeric temperatures. - This example needs neither Extract or Split from Columns nor Filtering; leave both empty. Add splitting rules only if source columns require them. For example,
vValue="23.5,24.5"can usesplit, delimiter,, and column count2to producevValue_0andvValue_1. This illustrative field does not require changes to this page's test table. Preview immediately after adding a rule, and check output columns before continuing. - If business requirements need filtering, add conditions and separately preview samples that should be retained and excluded. For example,
temperature > 0excludes nonpositive values and must not be assumed appropriate for a business allowing negative temperatures. Filtering excludes records; it does not merely hide a column. - Under Mapping, select
temperaturesand enter child table templatet_{device}. Map sourcetsto the target primary timestamp,temperatureto aDOUBLEdata column, anddeviceto a tag. For date-type times, check time zones first rather than directly applying millisecond-integer conversion settings. - Click Preview and check that device
d001generatest_d001, with times and temperatures matching source records. Fix null times, conversion errors, or child table name collisions first. Do not mask problems with current time or fixed device values. After a successful preview, check advanced options and error policies, then submit.
Preview does not write to the target or prove consistent types across all source rows. After submission, confirm the original task has started in the task list, then perform this page's ingestion verification. Do not repeatedly create tasks instead of troubleshooting.
4. Verification
- In the source database client, query the same object and time window, and retain the time zone, boundaries, and sampled values.
- Query the actual target child table in taosExplorer's Data Browser or the taos CLI. Filter by the same business time and check time, device tags, values, nulls, and precision.
- If the source can contain multiple rows for the same device and time, confirm the target primary-key strategy first. The source row count does not necessarily equal the number of unique target rows.
- After verifying one window, increase the device and time range. Verify tracking in continuous mode separately with newly committed data.
5. Stop, Resume, and Troubleshooting
Stop the original task, record verified windows and recent execution information, and retain task configuration and execution state. After resuming, check the interrupted window first. A checkpoint alone does not guarantee that there will be no rereads or gaps.
For connection failures, check the actual reading host, identity, and TLS first. For query failures, check expanded time types, object permissions, and the template. If reads succeed but nothing is written, check mappings and target errors. For detailed logs and metrics, see Logs and Performance.