This topic describes the scenarios, limitations, and procedure of data filtering by using SQL conditions after you select the migration or synchronization objects when you create a data migration or synchronization task.
Scenarios
When you create a data migration or synchronization task, you can specify SQL conditions to filter data. Only the data that meets the filter conditions will be migrated or synchronized to the target database. This feature allows you to filter data in multiple scenarios, such as scheduled data synchronization or migration, data table sharding, and historical and dirty data filtering.
Limitations
An SQL condition filters only fields of the current table. Cross-table filtering is not supported.
SQL conditions are supported in full migration, full synchronization, and incremental synchronization.
Do not perform DDL operations on columns to be filtered by SQL conditions. Otherwise, migration exceptions may occur.
Procedure
Configure a data migration or synchronization task to the Select Migration Objects or Select Synchronization Objects step.
For more information, see the topics about data migration or data synchronization tasks of the corresponding data source types.
After you specify the database objects to be migrated or synchronized, move the pointer over the table object in the Target Object(s) list in the Specify Migration Scope or Specify Synchronization Scope section, and click Settings.
In the Settings dialog box, specify a standard SQL
WHEREclause to filter data by row.The syntax of the SQL
WHEREclause is as follows:The system does not perform any case conversion on column names. Enter the correct column name and enclose the column name with escape characters (`), such as `col`.
The system supports filter conditions in standard SQL
WHEREclauses (=, !=, <, and > operators only), and migrates or synchronizes only data that meets theWHEREconditions, such as `id` > 200, to the target database.The system supports only time filter conditions in the format of yyyy-MM-dd HH:mm:ss or yyyy-MM-dd in the
WHEREclause. For example, if you want to retrieve incremental data after December 31, 2022, you can specify `date_now` > '2022-12-31' or `date_now` > '2022-12-31 00:00:00'.If you want to retrieve data within a specified period, use the
andororoperator. For example, if you want to retrieve data between December 31, 2021 and April 1, 2022, specify `init_date`>'2021-12-31' and `init_date`<'2022-04-01'.Use single quotation marks (') in the filter criteria, such as `address` in ('BEIJING','HANGZHOU').
Then, click Validate Syntax.
Click OK.
Complete subsequent task settings as prompted.