Skip to main content

Truncate Table

Data Manipulation

Synopsis

Clears every value and presence bit on the named virtual table, keeping it allocated for further $<table>.Field writes.

Schema

- truncate_table:
name: <string>
description: <text>
if: <script>
tag: <string>
disabled: <boolean>
ignore_failure: <boolean>
on_failure: <processor[]>
on_success: <processor[]>

Configuration

FieldRequiredDefaultDescription
nameYTable to clear. Must be one of the 12 registered tables (see Create Table), matched case-insensitively. Supports templating, e.g. name: "{{table}}".
descriptionNExplanatory note.
ifNCondition that must be true for the processor to run.
tagNIdentifier for this processor instance.
disabledNfalseWhen true, the processor is skipped.
ignore_failureNfalseContinue pipeline processing if the processor fails.
on_failureNSee Handling Failures.
on_successNSee Handling Success.

Details

What Gets Cleared

truncate_table resets every column of the named table to absent — clearing both its stored value and its presence bit, not just setting fields back to a zero value like "" or 0. A $<table>.Field == nil check reads true for every column immediately after truncation, exactly as it would on a freshly create_table-d table. The table's backing struct stays allocated, so subsequent $<table>.Field writes need no new create_table call.

If the truncated table is the entry's current output table (selected by Use Table), it stays selected — truncation only clears the struct's contents, it never changes which table use_table picked. The entry keeps marshaling from the same, now empty, table.

Failure Mode

Truncating a table that was never create_table-d on this entry is a no-op, not a failure — the table's member is already absent, so there is nothing to clear. Truncating a name that is not one of the 12 registered tables at all still fails the processor with unknown virtual table: "<name>", same as create_table and drop_table. Add ignore_failure: true to treat that as a soft skip.

Examples

Clearing a Table's Contents

Writing a field, then truncating before selecting the table as output...

{}
- create_table:
name: Syslog
- set:
field: $syslog.SyslogMessage
value: "first line"
- truncate_table:
name: Syslog
- use_table:
name: Syslog

SyslogMessage is cleared back to absent, so the marshaled table carries no fields at all...

{}

The Table Stays Allocated for Further Writes

Truncating, then writing a new value into the same table without calling create_table again...

{}
- create_table:
name: Syslog
- set:
field: $syslog.SyslogMessage
value: "first line"
- truncate_table:
name: Syslog
- set:
field: $syslog.SyslogMessage
value: "second line"
- use_table:
name: Syslog

The write succeeds immediately — truncate_table only clears contents, it never deallocates the table...

{
"SyslogMessage": "second line"
}

No-Op on a Table That Was Never Created

Truncating Syslog before anything has ever create_table-d it...

{
"message": "untouched"
}
- truncate_table:
name: Syslog

No error is raised — an uncreated table has nothing to clear, and the event passes through unmodified...

{
"message": "untouched"
}

Failing on an Unknown Table Name

Naming a table that isn't one of the 12 registered schemas...

{}
- truncate_table:
name: Frobnicate
ignore_failure: true

Frobnicate isn't a registered table, so — unlike an uncreated but known table — this fails; ignore_failure skips the failure...

{}