Skip to content

Commit 19b801d

Browse files
fix: For log-based streams, update _parse_column_value to handle null values (#701)
Supersedes #700 --------- Co-authored-by: Rober Parton <partonrobertjames@gmail.com>
1 parent f46b7ce commit 19b801d

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

tap_postgres/client.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,33 @@ def _parse_column_value(self, column, cursor):
413413
# array types returns a string encoded in sql format, e.g. '{a,b}'
414414
# https://github.com/eulerto/wal2json/issues/221#issuecomment-1025143441
415415
if column["type"] == "text[]":
416-
return psycopg2.extensions.STRINGARRAY(column["value"], cursor)
417-
418-
return column["value"]
416+
value = column.get("value")
417+
if value is None:
418+
return None
419+
return psycopg2.extensions.STRINGARRAY(value, cursor)
420+
421+
# Handle null values explicitly.
422+
# wal2json represents nulls as JSON null, which becomes None in Python.
423+
value = column.get("value")
424+
if value is None:
425+
return None
426+
427+
# For numeric types, check if empty string should be treated as null.
428+
column_type = column.get("type", "")
429+
numeric_types = [
430+
"int",
431+
"numeric",
432+
"decimal",
433+
"real",
434+
"double",
435+
"float",
436+
"bigint",
437+
"smallint",
438+
]
439+
if value == "" and any(numeric_type in column_type for numeric_type in numeric_types):
440+
return None
441+
442+
return value
419443

420444
def logical_replication_connection(self):
421445
"""A logical replication connection to the database.

0 commit comments

Comments
 (0)