pfx-sql:truncate

Summary: Remove all data from an external SQL database table. This is a fast, unfiltered delete of all rows.


URI Format

pfx-sql:truncate?table=myTable&dataSource=myDb

Parameters

Parameter

Type

Default

Required

Description

dataSource

String

dataSource

No

Name of the Spring DataSource bean

table

String


Yes

Target database table to truncate

dialect

SQLDialect

MYSQL

No

SQL dialect

Examples

Basic Truncate

XML
<to uri="pfx-sql:truncate?table=staging_products&amp;dataSource=myDb"/>

Truncate Before Full Load

XML
<route id="fullLoad">
    <from uri="timer://fullSync?repeatCount=1"/>
    <!-- Clear staging table -->
    <to uri="pfx-sql:truncate?table=staging_products&amp;dataSource=myDb"/>
    <!-- Fetch and load fresh data -->
    <to uri="pfx-api:fetch?objectType=P&amp;filter=allProducts"/>
    <to uri="pfx-sql:insert?table=staging_products&amp;mapper=stagingMapper&amp;dataSource=myDb"/>
</route>

Truncate with PostgreSQL

XML
<route id="truncatePostgres">
    <from uri="timer://cleanup?repeatCount=1"/>
    <to uri="pfx-sql:truncate?table=temp_data&amp;dataSource=pgDb&amp;dialect=POSTGRESQL"/>
</route>

Common Pitfalls

Problem

Cause

Fix

Accidentally deleted all data

Truncate removes all rows with no filter

Use delete with a filter if you only want to remove specific records

Foreign key constraint error

Table has foreign key references from other tables

Truncate dependent tables first, or use delete instead

Missing table parameter

Required parameter not provided

Add table=yourTable to the URI

See Also

  • pfx-sql Component — Parent reference

  • pfx-sql:delete — Delete specific rows using a filter