replace_empty_string
replace_empty_string · C trigger function that replaces empty strings with NULL
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100681 | replace_empty_string | replace_empty_string | 1.0 | UTIL | BSD-2-Clause | C |
Usage
Sources:
replace_empty_string provides a generic row trigger that changes zero-length string values to SQL nulls before an insert or update. It is useful for Oracle-oriented migrations where empty strings are expected to behave like null, but it changes data semantics for every string-category column on the attached table.
Core Workflow
Install the extension and attach its trigger function as a BEFORE row trigger to each table that needs the conversion:
The trigger scans all attributes whose PostgreSQL type category is string, unwraps domains to their base type, and replaces only values whose stored length is zero. Whitespace-only strings are left unchanged.
Warning Mode
Pass the literal trigger argument on to emit a warning for each column changed:
Any absent or different first argument leaves warnings disabled. Warning mode can produce substantial log and client-message volume during bulk loads, so use it for migration discovery or testing rather than as a default observability mechanism.
Operational Notes
The function must be invoked by a row-level BEFORE INSERT OR UPDATE trigger; direct calls, statement triggers, after triggers, and delete events are rejected by the C implementation. Existing stored rows are not rewritten when the trigger is created. Backfill them explicitly if uniform historical data is required.
Version 1.0 is relocatable and declares no preload or extension dependency. The upstream README states that this code was merged into Orafce, so evaluate the maintained Orafce implementation for new Oracle-compatibility deployments. Converting empty strings to null can affect NOT NULL constraints, unique indexes, predicates, application serialization, and length checks; test those semantics before attaching the trigger broadly.