PostgreSQL – Equivalents to Oracle DML Error Logging
Capabilities, Workarounds, and Disadvantages (Documentation)
Baseline Statement
PostgreSQL does not provide a native, engine-level equivalent to Oracle DML Error Logging (LOG ERRORS ... REJECT LIMIT ...) for INSERT, UPDATE, DELETE, or MERGE.
In PostgreSQL, when a set-based DML statement encounters an error for any row, the default behavior is that the entire statement fails. If the statement is executed inside an explicit transaction block, the transaction enters an error state and must be rolled back before further commands can succeed.
As a result, equivalent behavior can only be achieved through workarounds. Each workaround matches a specific subset of Oracle’s behavior, but none reproduces Oracle’s single-statement, engine-native “log-and-continue” semantics.
What Oracle Provides (Reference Behavior)
Oracle DML Error Logging provides the following behavior in one statement:
PostgreSQL does not implement this feature as a single database-engine mechanism, so the alternatives are patterns that approximate parts of this behavior.
Equivalent Patterns in PostgreSQL
1. Pre-validation and Data Filtering (Set-based Reject by Rules)
Description
Invalid rows are excluded before they reach the target table. Reject logging is implemented by explicitly inserting excluded rows into a separate reject table.
This approach is set-based and fast, but it only works for validation rules that can be expressed in SQL predicates.
Typical Implementation
Disadvantages
2. Handling Uniqueness Conflicts with ON CONFLICT (Partial Equivalent)
Description
PostgreSQL supports INSERT ... ON CONFLICT for handling unique constraint conflicts without failing the statement. This can be used to approximate Oracle behavior for the specific case of unique or primary key violations.
This pattern can be combined with separate reject logging to record rows skipped due to conflict.
Disadvantages
3. Row-by-Row Exception Capture in PL/pgSQL (Closest Functional Behavior)
Description
A procedure iterates over input rows, attempts to apply DML per row, and catches exceptions per row. Failed rows are written to a reject table, and processing continues.
This is the closest approximation to Oracle’s “log-and-continue” behavior, because it captures real database errors and continues execution.
Disadvantages
4. Two-Phase Load via Staging (Typed Target Load with Reject Logging)
Description
Data is first loaded into a staging table designed for ingestion (often with permissive types, such as text). A second phase performs validation and type conversion into the target schema, writing rejected rows into a reject table.
This is the most common pattern for production ETL pipelines in PostgreSQL, particularly when data arrives from files or external systems.
Disadvantages
Error vs Exception Handling in PostgreSQL (Important Distinction)
Oracle separates “row-level DML errors that can be logged” from “statement-level fatal errors that must be raised.” PostgreSQL does not provide a comparable engine-level routing mechanism during set-based DML.
In PostgreSQL:
Comparative Summary (PostgreSQL Perspective)
PostgreSQL does not support SQL-native row-level reject logging with continuation in a single DML statement. Equivalent behavior requires one of the following:
Final Conclusion
PostgreSQL provides no direct equivalent to Oracle DML Error Logging. Its alternatives are architectural patterns rather than a single database feature. The correct approach depends on the required scope of rejection handling:
One-line Takeaway
PostgreSQL cannot reproduce Oracle’s set-based, engine-native “log row errors and continue” behavior in a single statement; equivalent solutions require pre-validation, conflict handling, procedural exception capture, or staging-based ETL design.