From 5c658c28f86a4d236df73bdeaa6b2c977ed6935c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez=20Mondrag=C3=B3n?= Date: Thu, 7 Dec 2023 20:17:22 -0600 Subject: [PATCH] fix: Use `nulls_first` to order results in incremental SQL streams --- singer_sdk/streams/sql.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/singer_sdk/streams/sql.py b/singer_sdk/streams/sql.py index e605471dc5..f235455162 100644 --- a/singer_sdk/streams/sql.py +++ b/singer_sdk/streams/sql.py @@ -5,6 +5,8 @@ import abc import typing as t +from sqlalchemy import nulls_first + import singer_sdk.helpers._catalog as catalog from singer_sdk._singerlib import CatalogEntry, MetadataMapping from singer_sdk.connectors import SQLConnector @@ -189,7 +191,7 @@ def get_records(self, context: dict | None) -> t.Iterable[dict[str, t.Any]]: if self.replication_key: replication_key_col = table.columns[self.replication_key] - query = query.order_by(replication_key_col) + query = query.order_by(nulls_first(replication_key_col)) start_val = self.get_starting_replication_key_value(context) if start_val: