{
  "schema_version": 2,
  "id": "integrate/redis-data-integration/data-pipelines/transform-examples/redis-opcode-example",
  "title": "Using the operation code",
  "url": "https://redis.io/docs/latest/integrate/redis-data-integration/1.19.1/data-pipelines/transform-examples/redis-opcode-example/",
  "summary": "",
  "content": "\nThe operation code (`opcode`) is a metadata field that indicates the type of operation that generated the change in the source database. It can be useful for tracking changes and understanding the context of the data being processed.\n\nThe opcode is only available in the [full row format](https://redis.io/docs/latest/integrate/redis-data-integration/1.19.1/data-pipelines/transform-examples/redis-row-format#full), and can be accessed in the `transform` and `output` sections of the job file.\n\nIt has one of the following values:\n\n| Opcode | Operation | Notes |\n|--------|-----------|-------|\n| `c` | Create row |  |\n| `u` | Update row |  |\n| `d` | Delete row |  |\n| `r` | Read row (snapshot) | Applies only to snapshots. |\n| `t` | Truncate table | PostgreSQL specific. |\n| `m` | Message event | PostgreSQL specific. |\n\n\nYou can add the value of the operation code to the output, and also use it in a conditional expression to modify the behavior of the job. The following examples demonstrate the different use-cases.\n\n### Adding the operation code to the output\n\nUse the `add_field` transformation to add a new field that contains the value of the `opcode` field from the source data. Note that the fields must be prefixed with `after` to be included in the output.\n\n\n```yaml\nname: Add operation code to employee\nsource:\n  schema: public\n  table: employee\n  row_format: full\n\ntransform:\n  # add the operation code to the data\n  - uses: add_field\n    with:\n      field: after.operation_code\n      expression: opcode\n      language: jmespath\n```\n\n\n### Filtering operation by output code.\n\nIn some cases you may want to ignore certain operations (for example, you may not be interested in deletions). Use the `filter` transformation to filter out any operations you don't need to process.\n\n```yaml\nname: Filter out delete operations\nsource:\n  schema: public\n  table: employee\n  row_format: full\n\ntransform:\n  - uses: filter\n    with:\n      expression: opcode != 'd'\n      language: jmespath\n```\n\n### Modifying the output based on the operation code\n\nThe previous example filters out specific operations, but you can also modify the output based on the operation code. For example, you can add a new field that tracks the status of the record based on the operation code.\n\nNote that when a source record is deleted, you must modify the value of the `opcode` field if you want to prevent the corresponding record in the target database from being removed automatically.\n\n```yaml\nname: Track status based on operation code\nsource:\n  schema: public\n  table: employee\n  row_format: full\n\ntransform:\n  - uses: add_field\n    with:\n      fields:\n        # Here you set the value of the field based on the value of the opcode field\n        - field: after.status\n          expression: opcode == 'd' \u0026\u0026 'inactive' || 'active'\n          language: jmespath\n\n        # You have to change the value of the opcode field to prevent deletion\n        - field: opcode\n          expression: opcode == 'd' \u0026\u0026 'u' || opcode\n          language: jmespath\n```\n",
  "tags": ["docs","integrate","rs","rdi"],
  "last_updated": "2026-09-19T17:55:58-07:00"
}
