Oracle automatically converts empty strings ('') to NULL in VARCHAR2 columns. PostgreSQL preserves empty strings as distinct from NULL. This difference can cause application logic errors and test failures during migration.
Oracle:
- Empty string (
'') is always treated asNULLin VARCHAR2 columns WHERE column = ''never matches rows; useWHERE column IS NULL- Cannot distinguish between explicit empty string and
NULL
PostgreSQL:
- Empty string (
'') andNULLare distinct values WHERE column = ''matches empty stringsWHERE column IS NULLmatchesNULLvalues
-- Oracle behavior
INSERT INTO table (varchar_column) VALUES ('');
SELECT * FROM table WHERE varchar_column IS NULL; -- Returns the row
-- PostgreSQL behavior
INSERT INTO table (varchar_column) VALUES ('');
SELECT * FROM table WHERE varchar_column IS NULL; -- Returns nothing
SELECT * FROM table WHERE varchar_column = ''; -- Returns the rowUpdate logic that assumes empty strings convert to NULL:
-- Preserve Oracle behavior (convert empty to NULL):
column = NULLIF(param, '')
-- Or accept PostgreSQL behavior (preserve empty string):
column = paramReview code that checks for NULL and ensure it handles empty strings appropriately:
// Before (Oracle-specific)
if (value == null) { }
// After (PostgreSQL-compatible)
if (string.IsNullOrEmpty(value)) { }Update assertions to be compatible with both behaviors:
// Migration-compatible test pattern
var value = reader.IsDBNull(columnIndex) ? null : reader.GetString(columnIndex);
Assert.IsTrue(string.IsNullOrEmpty(value));Decide whether to:
- Convert existing
NULLvalues to empty strings - Convert empty strings to
NULLusingNULLIF(column, '') - Leave values as-is and update application logic