sling-cli
sling-cli copied to clipboard
MSSQL "The ORDER BY clause is invalid"
Issue Description
-
Description of the issue: Sling creates a subquery when removing columns, which causes an error in Microsoft SQL Server. As a workaround, https://stackoverflow.com/a/60232533 or remove the subquery. The excluded column never appears in the Sling-generated query, so the subquery is unnecessary.
-
Sling version (
sling --version): 1.4.5 -
Operating System (
linux,mac,windows): linux amd64 -
Replication Configuration:
...
a.at:
primary_key: OPId
select: [-AT]
...
- Log Output (please run command with
-d):
2025-04-21 21:59:47 DBG Sling version: 1.4.5 (linux amd64)
2025-04-21 21:59:47 DBG type is db-db
2025-04-21 21:59:47 DBG using: {"columns":null,"mode":"incremental","select":["-AT"],"transforms":null}
2025-04-21 21:59:47 DBG using source options: {"empty_as_null":false,"datetime_format":"AUTO","max_decimals":-1}
2025-04-21 21:59:47 DBG using target options: {"datetime_format":"auto","file_max_rows":0,"max_decimals":-1,"use_bulk":true,"add_new_columns":true,"adjust_column_type":false,"column_casing":"normalize"}
2025-04-21 21:59:47 INF connecting to source database (sqlserver)
2025-04-21 21:59:47 DBG opened "sqlserver" connection (conn-sqlserver-ViM)
2025-04-21 21:59:47 INF connecting to target database (sqlserver)
2025-04-21 21:59:47 DBG opened "sqlserver" connection (conn-sqlserver-qMg)
2025-04-21 21:59:47 INF getting checkpoint value
2025-04-21 21:59:47 DBG select max("Updated") as max_val from "a"."at"
2025-04-21 21:59:47 INF reading from source database
2025-04-21 21:59:47 DBG select "OPId", "Created", "Updated", "ST" from (
select OPId, Created, Updated, ST from "a"."at" where ("Updated" > cast('2025-01-21 14:22:17.3884541' as datetime2)) order by "Updated" asc
) t
2025-04-21 21:59:47 DBG closed "azuresql" connection (conn-sqlserver-ViM)
2025-04-21 21:59:47 DBG closed "azuresql" connection (conn-sqlserver-qMg)
2025-04-21 21:59:47 INF execution failed
--- task_run.go:136 func2 ---
~ Could not ReadFromDB
--- task_run.go:782 runDbToDb ---
~ Could not BulkExportFlow
--- task_run_read.go:198 ReadFromDB ---
--- database.go:2410 BulkExportFlow ---
~ dataflow error while waiting for ready state
--- dataflow.go:654 WaitReady ---
~ SQL Error for:
select "OPId", "Created", "Updated", "ST" from (
select OPId, Created, Updated, ST from "a"."at" where ("Updated" > cast('2025-01-21 14:22:17.3884541' as datetime2)) order by "Updated" asc
) t
mssql: The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP, OFFSET or FOR XML is also specified.
context canceled
Thanks for raising. This is fixed for v1.4.6.
Fixed for release 1.4.7