mitre / data-owner-tools

Tools for the Childhood Obesity Data Initiative (CODI) data owners and partners to use in record linkage
Apache License 2.0
5 stars 8 forks source link

Fix extract on MSSQL, conditionally add nulls last based on DB engine #49

Closed dehall closed 1 year ago

dehall commented 1 year ago

This PR fixes the bug when trying to extract from a MS SQL Server db, where trying to sort address history by date with nulls last doesn't work due to MS SQL not supporting NULLS LAST.

The idea here is to only add NULLS LAST to the query when needed, ie, on postgres and oracle. Fortunately on MS SQL it already sorts in the order we want by default, so we don't have to do anything else.

Note: I tested this myself on postgres and MSSQL, but not oracle as I'm having a rough time trying to get the script to run against the docker image I set up. Based on testing with pure SQL though, oracle does support NULLS LAST

I also left a TODO to test on MySQL, but we don't currently have any partners who use it so we can defer that to later