dup_field - Linux


dup_field copies specified fields from source_table to target_table while preserving data integrity and performance. It automatically handles data type conversion, field addition, and update operations.


dup_field source_table target_table [field1 field2 ...]


  • -y: Overwrite existing target fields without confirmation.
  • -v: Enable verbose output, providing detailed progress information.
  • –dry-run: Preview the changes without making any modifications to the tables.


Example 1: Copy specific fields

Copy the name and age fields from source_table to target_table:

dup_field source_table target_table name age

Example 2: Copy all fields (except a few)

Copy all fields except id and created_at from source_table to target_table:

dup_field source_table target_table --exclude id created_at

Example 3: Dry run

Preview the changes without modifying the tables:

dup_field source_table target_table name age --dry-run

Common Issues

  • Ensure that both source_table and target_table exist and have the correct permissions.
  • Check that the specified fields exist in source_table and are compatible with the data types in target_table.
  • Avoid using dup_field on very large tables, as it can be resource-intensive. Consider using a batch processing tool for such scenarios.


Example 1: Post-insertion data migration

Automatically copy new records from source_table to target_table after insertion:

pg_triggers --create --trigger update_target_table --table source_table --whenever insert --execute 'dup_field source_table target_table name age'

Example 2: Data synchronization

Synchronize data between table1 and table2 on a regular basis using a cron job:

0 0 * * * dup_field table1 table2 --overwrite

Related Commands