Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(postgres): mark invalid bigint incremental cursor as non-retryable (#74359)

Tom Owersf9c987bcc872
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py
index d864d7c61f48..dd87017f8e4c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py
@@ -642,15 +642,18 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa
# an existing column in place, so retrying won't help — the table must be reset and
# fully re-synced to adopt the new type.
"Source column type changed": "A column's type changed in your source database (for example an integer column was widened to bigint) and no longer fits the type we stored. We can't widen an existing column in place — please reset and fully re-sync this table to adopt the new type.",
- # Raised by the source Postgres when the incremental query compares an integer column
- # against a non-integer cursor value, e.g. `WHERE "id" > '1.5'`. `_build_query` renders
- # the stored `incremental_field_last_value` as a SQL literal, so a fractional/non-integer
- # cursor produces `InvalidTextRepresentation: invalid input syntax for type integer`.
- # This is deterministic — every retry re-runs the identical failing query — and signals a
- # type mismatch between the incremental field and its data. The volatile offending value
- # (`: "1.5"`) is excluded from the match. Coercing the cursor here would change sync
- # semantics (risk of skipped/duplicated rows), so stop and ask the user to reset.
+ # Raised by the source Postgres when the incremental query compares an integer/bigint
+ # column against a non-integer cursor value, e.g. `WHERE "id" > '1.5'` or
+ # `WHERE "id" > '2026-04-26T20:58:57.557000'`. `_build_query` renders the stored
+ # `incremental_field_last_value` as a SQL literal, so a fractional/timestamp-shaped
+ # cursor produces `InvalidTextRepresentation: invalid input syntax for type integer` (or
+ # `bigint`, depending on the column's declared width). This is deterministic — every retry
+ # re-runs the identical failing query — and signals a type mismatch between the
+ # incremental field and its data. The volatile offending value is excluded from the match.
+ # Coercing the cursor here would change sync semantics (risk of skipped/duplicated rows),
+ # so stop and ask the user to reset.
"invalid input syntax for type integer": "PostHog tried to resume this table's incremental sync from a non-integer cursor value against an integer incremental field, which your database rejects. This usually means the incremental field's type doesn't match its data. Please reset and fully re-sync this table, or pick a different incremental field.",
+ "invalid input syntax for type bigint": "PostHog tried to resume this table's incremental sync from a non-integer cursor value against a bigint incremental field, which your database rejects. This usually means the incremental field's type doesn't match its data. Please reset and fully re-sync this table, or pick a different incremental field.",
# Raised (ObjectNotInPrerequisiteState, SQLSTATE 55000) when a selected materialized view
# was created `WITH NO DATA` and never refreshed — every SELECT against it fails until the
# customer runs `REFRESH MATERIALIZED VIEW`. Deterministic and outside our control, so
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py
index e20f54faca08..00135c1cb677 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py
@@ -798,6 +798,8 @@ class TestPostgresSourceNonRetryableErrors:
[
'invalid input syntax for type integer: "1.5"',
'InvalidTextRepresentation: invalid input syntax for type integer: "1.5"',
+ 'invalid input syntax for type bigint: "2026-04-26T20:58:57.557000"',
+ 'InvalidTextRepresentation: invalid input syntax for type bigint: "2026-04-26T20:58:57.557000"',
],
)
def test_non_integer_incremental_cursor_errors_are_non_retryable(self, source, error_msg):