SQDR macros¶
An SQDR macro is a named, reusable piece of SQL for derived column expressions. Define it once for the Replicator Service; every subscription can use it, and a change applies to all of them the next time their SQL is built.
Use a macro when:
- many subscriptions need the same expression, such as a date conversion or a data cleanup;
- the SQL depends on the source database: define the same name for Oracle, SQL Server, Db2 and so on, and each subscription uses the one for its source;
- an expression is long or error-prone and you want to write and test it once.
The built-in capture metadata macros (@TS, @TYPE, @JED, ...) work
differently and can't be redefined.
Manage macros¶
On the SQDR Macros tab of Service Settings, or from a derived column's Macros panel.

- Remove Macro: subscriptions that use the macro then keep
@NAMEunresolved in their expression, which usually fails at the next run. - Export Macros saves all macros to
sqdr_macros.json; Import Macros reads such a file, for example to copy them from a test server to production. - The Replicator Service caches macros, so a change can take up to 5 minutes to be used.
Define a macro¶
| Field | What it's for |
|---|---|
| Macro | The signature: the name, and its parameters if it takes any. See below. Names aren't case-sensitive. |
| DBMS Type | The source database type the macro is for, or <global> for all. |
Signature and parameters¶
A signature has one of three forms:
| Signature | Meaning |
|---|---|
NAME |
No parameters. |
NAME(p1, p2) |
Two parameters, p1 and p2. |
NAME^p1^p2 |
The same, in caret form. |
In Macro Value, write ^p1 where the value of parameter p1 goes. Two parameters are always available:
| Parameter | Value |
|---|---|
^st |
The source table name, in quotes ('ORDERS'). |
^~st |
The source table name, without quotes. |
A macro value can call other macros (up to 100 levels deep).
Names you can't use¶
The names of the capture metadata macros are reserved: SCHEMA, LT, DSN, OBJECT, JED, TX, TS, TYPE,
SEQ, RRN, MBR, tz, null and skip, in any case.
Use a macro¶
Start a derived column's Expression (or Staging Expression) with the macro:
| Call | Example |
|---|---|
@NAME |
@CLEANTEXT |
@NAME(arg1, arg2) |
@PADLEFT(CUSTNO, 10) |
@NAME^arg1^arg2 |
@PADLEFT^CUSTNO^10 |
- The expression must start with the macro (
@); an@later in the expression isn't expanded. - In the caret form, an argument can be quoted (
'...'or"..."), in parentheses, or another macro call. - Every parameter needs an argument; otherwise the expression fails with "Macro @NAME expects N argument(s), but got M".
- An undefined macro is left as it is, and the source database then reports an error.
- For a literal
@,^, quote or backslash, put a backslash before it (\@,\^,\',\",\\);\n,\tand\rare a newline, a tab and a carriage return.
Which definition is used¶
When a macro name is defined for several database types:
- Baseline: the definition for the source's database type; if there's none, the
<global>one. - Changes (incremental subscriptions): changes are processed in the Db2 for LUW staging database. The Staging
Expression (or, if empty, the Expression) is resolved with the
UDB(Db2 for LUW) and<global>definitions first, then with those of the source's type.
So for an incremental subscription from Oracle, define an Oracle version for the baseline and a UDB version for
changes, or one <global> definition valid in both.
Example¶
Oracle and Db2 for LUW sources store an order date as a YYYYMMDD string; the destination needs a DATE.
| Macro | DBMS Type | Macro Value |
|---|---|---|
TODATE(col) |
Oracle |
TO_DATE(^col, 'YYYYMMDD') |
TODATE(col) |
UDB |
DATE(TO_DATE(^col, 'YYYYMMDD')) |
A derived column with the expression @TODATE(ORDER_DT) and the data type DATE then works for the baseline from
Oracle, for the changes processed in the staging database, and for Db2 for LUW sources.
PowerShell¶
The SQDR PowerShell cmdlets manage macros from scripts. -ConnStr is the Replicator Service (default
127.0.0.1:7738); -DbmsType is the database type code (0 for <global>).
| Cmdlet | What it does |
|---|---|
Show-SqdrMacros [-DbmsType n] [-IncludeGlobal $true] [-JsonFileOut file] |
Lists macros, or writes them to a file. |
Add-SqdrMacro -MacroSignature s -DbmsType n -MacroValue v [-Comment c] |
Defines a macro. |
Set-SqdrMacro -Id id -MacroSignature s -DbmsType n -MacroValue v [-Comment c] |
Changes a macro. |
Remove-SqdrMacro -MacroName name -DbmsType n |
Deletes a macro. |
Export-SqdrMacros -JsonFileOut file |
Exports all macros. |
Import-SqdrMacros -JsonFile file |
Imports macros. |
| Code | Database type | Code | Database type |
|---|---|---|---|
| 0 | <global> |
8 | MySQL |
| 2 | SQL Server | 9 | Informix |
| 3 | Db2 for i (iSeries) |
11 | PostgreSQL |
| 4 | Db2 for z/OS (DB2) |
20 | Snowflake |
| 5 | Db2 for LUW (UDB) |
22 | Databricks |
| 7 | Oracle | 23 | BigQuery |