This topic describes the scenarios, limits, and procedure of data filtering by using SQL conditions after you select the migration objects when you create a data migration project.
Scenarios
When you create a data migration project, you can specify SQL conditions to filter data. Only the data that meets the filter conditions will be migrated to the destination 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.
Limits
An SQL condition filters only fields of the current table. Cross-table filtering is not supported.
SQL conditions are supported in full migration and incremental synchronization.
Procedure
Create a data migration project and configure it to the Select Migration Objects step.
For more information, see the topic about creating a data migration project between the corresponding data sources in the Data migration chapter.
Select the migration object, and then move the pointer over the target object in the Destination Objects list on the right of the Specify Migration Scope section.
Click Settings.
In the Settings dialog box, specify a standard SQL WHERE clause to filter data by row.
Syntax of the SQL WHERE clause:
The system does not perform any case conversion on column names. Enter the correct column name and enclose the column name with escape characters (`). Example:
`col`
.Filter conditions support standard SQL WHERE statements. Only
=
,! =
,<
, and>>
operators are supported, and only data that meets the WHERE condition will be synchronized to the destination database. Example:`id`
> 200.Filter conditions support filtering based on time conditions. However, take note of the format requirements for time in SQL WHERE statements, which is
yyyy-MM-dd HH:mm:ss
oryyyy-MM-dd
.For example, if you want to filter incremental data after December 31, 2022, enter
`date_now` > '2022-12-31'
or`date_now` > '2022-12-31 00:00:00'
.If you need to filter data within a specified period, use the `and` or `or` statement. For example, to filter data between December 31, 2021 and April 1, 2022, enter
`init_date`>'20211231' and `init_date`<'20220401'
.Use single quotation marks (') in the filter criteria. Example:
`address` in ('BEIJING','HANGZHOU')
.
Click Validate Syntax.
Click OK.
Complete subsequent project settings as prompted.